读书人

[Relearn Spring] 2.1 IoC - Misc 一

发布时间: 2012-10-07 17:28:51 作者: rapoo

[Relearn Spring] 2.1 IoC - Misc 1
1. BeanFactory V.S. ApplicationContext

BeanFactory only handles the managements of beans.
ApplicaitonContext is build upon BeanFactory (by inheritance) but add enterprise support to it, such as AOP/Resource etc.

2. BeanDefinition will hold the metadata for beans, such as scope, lazy-initialization and so on.

3. You can use your self-defined to create your bean, just by XML configuration

 <bean id="exampleBean"factory-bean="serviceLocator"factory-method="createInstance"/>  



3.
 <ref local="someBean"/>    
means that the container will try to seek this bean in the same xml file.


4.
<bean id="beanOne" depends-on="manager"/>
will tell the container to initialize "beanOne" after it initializes "manager"


5.Inject "local" variable

package fiona.apple;// no more Spring imports!public abstract class CommandManager {public Object process(Object commandState) {// grab a new instance of the appropriate Command interfaceCommand command = createCommand();// set the state on the (hopefully brand new) Command instancecommand.setState(commandState);return command.execute();}// okay... but where is the implementation of this method?protected abstract Command createCommand();}



<bean id="commandManager" bean="command"/></bean>

读书人网 >软件架构设计

热点推荐