Detailed process of spring beanfactory bean instantiationSpring has never been used for a long time. Now the company only uses struts2 + hibernate, Which is unfamiliar with spring. However, when we open the original project, we are still very friendly-long-time friends!
Bean instantiation in
First, build the spring environment:With the introduction of the jar package in the Lib directory and add to path, it is not too much to say.Ii. three ways to instantiate a bean:First, let's start by writing two Java classes:Interface class:Public interface Personservice {public abstract void Save ();Implementation class:public class Personservicebean implements Personservice {@Overridepublic void Save () {System.out.println ("I Am the Save () method"
Http://flysnow.iteye.com/blog/733785 #In most cases, the bean in the container is of the singleton type. If a singleton bean references another Singleton bean, or a non-singleton bean references another non-singleton bean, generally, you can define a
: Construction methodExecutive Initanddestroyseqbean:postconstructExecutive Initanddestroyseqbean:afterpropertiessetExecutive Initanddestroyseqbean:init-methodExecutive Initanddestroyseqbean:predestroyExecutive Initanddestroyseqbean:destroyExecute initanddestroyseqbean:destroy-method.We introduce the relevant methods before and after instantiation of spring Bean:@PostConstruct Init-method destroy-method aft
loads the context definition file FileSystemXmlApplicationContext from the class path: An application context that loads the context file XmlWebApplicationContext from the file system: A Spring-based web Application System context that loads context definition files from the web application context
Public class TestMain {public static void main (String [] args) {// ApplicationContext ctx = new ClassPathXmlApplicationContext ("applicationContext. xml
I. knowledge points
The bean post-processor allows additional bean processing before and after the initialization callback method. The main feature of the bean postprocessor is to process all bean instances in the IOC container one by one, not just a single bean instance. In
In the previous blog mentioned in the container launch Get Beandefinition object has a scope property. This property controls the scope of the Bean object. This section describes the scope and life cycle of the bean, and how it does not.
I. Scope of the BeanThe bean container starts reading the bean's XML configuration file, and then converts each
In the introduction to the spring IOC container launch, a rough analysis of the launch process of the IOC container was made on the basis of Classpathxmlapplicationcontext, with no detailed description of some of the more complex steps, This article begins with some of the more complex steps that are analyzed. This article analyzes the parsing and loading process of the bean definition of the IOC container
I. Configuring Beans with Annotations1.1 OverviewIn contrast to XML, configuring beans in an annotated manner is more concise and elegant, and fits well with the concept of MVC component development, and is a common use in development.1.2 Using annotations to identify components① Normal components:@Component: identify a component managed by the Spring IOC container② Persistence layer components:@Respository: identifies a persistence layer component ma
The structure directory for the entire example is as follows:1. Customizing a resource fileCom.sxd.name = Shen 9th Wood com.sxd.secret = ${random.value}com.sxd.intvalue = ${random.int}com.sxd.uuid = ${random.uuid} Com.sxd.age= ${random.int (+)}com.sxd.resume = CV: ① name: ${com.sxd.name} ② Age: ${com.sxd.age}2. Bind attributes from a resource file to a bean PackageCom.sxd.beans;Importorg.springframework.b
In Spring, inheritance is used to set up a bean for a support bean to share a common value, property, or configuration. A child bean or inherited bean can inherit the configuration, properties, and some properties of its parent bean
First, the bean initialization and destructionIn our actual development, we often encounter beans before or after the use of the necessary operations, spring on the Bean's life-cycle operations to provide support. There are two ways to use Java Configuration and annotation configurations:(1) How Java is configured: Use the Initmethod and Destroymethod of the @Bean
When you configure a bean, you create a formula (recipe) for the actual class instance through the bean's configuration. The bean configuration is a recipe idea that is important because it means that, like a class, you can create many instances with a recipe.
Not only can you control the dependencies and configuration values that are injected into objects created by a particular
Direct use of JUnit to test the shortage of Spring programs
you need to manually fetch the bean using hard coding: in the test case, we need to get the target Bean to be tested from the SPIRNG container by means of the Applicationcontext.getbean () method, and also to do the modeling operation.
The database site is vulnerable to damage: The test meth
, it can be set to any artist and album name you want. Now, we can putThe existing sgtpeppers is replaced with this class:we use the But this time we did not use the "ref" attribute to refer to other beans, but instead used the Value property, which indicates that the given value is to be injected into the constructor in literal form . What should this example look like if you were to use a C-namespace? The first case is the name of the reference constructor parameter:in terms of assembling
Spring Kernel Research-managing bean Declaration cycles One (Initializingbean and Init-method)
Initializingbean
SPIRNG's Initializingbean provides a way for the bean to define the initialization method. Initializingbean is an interface that contains only one method: Afterpropertiesset ().The bean implements this
The core containers of spring include: core, beans, context, express language four modules. So for a simple spring project, the basic thing is to rely on the following three jar packages: Dependency> groupId>Org.springframeworkgroupId> Artifactid>Spring-coreArtifactid> version>4.3.8.RELEASEversion> Dependency> Dependency> grou
1. Introduction
Under the SSH framework, suppose we put the configuration file under the Src/datasource.properties path of the project, and the spring configuration file is also src/ Applicationcontext.xml path, then we can read the configuration file with spring's property-placeholder and inject it into the bean. In the program, we can get the injected value based on the Bean's ID. This allows us to read t
Spring Bean:the object called the Bean is the backbone of the application and is managed by the spring IOC container. A bean is an instantiated, configured, assembled, and managed object by the spring IOC container. Official website api:a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.