spring: three kinds of bean details of the way to create objects Bean

<! - Bean created three ways -> 
<! - the first approach, created with the default constructor
after the use of the label in spring bean configuration file, together with the id and class attributes, and no property and labels Time.
The default constructor is used to create a bean object, at this time if the class has no default constructor, the object can not be created
->
<bean id="accountService" class="cn.flypig666.service.impl.AccountServiceImpl"></bean>

 
<- The second way:! Use ordinary factory to create objects (objects created using methods in a class, and into spring container) ------------ create a jar package this class may be used when the method of 
factory-bean: Specifies plant the bean
factory-method: Specifies which method to get the object
->
<bean id="instanceFactory" class="cn.flypig666.factory.InstanceFactory"></bean>
<bean id="accountService" factory-bean="instanceFactory" factory-method="getAccountService"></bean>

 
<- The third way:! Create an object (static method to create an object using a class, and store spring container) static method in the plant -> 
<bean the above mentioned id = "the AccountService" = class "CN. flypig666.factory.StaticInstanceFactory "factory-method =" getAccountService "> </ bean>

Guess you like

Origin www.cnblogs.com/flypig666/p/11511512.html
Recommended