[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" class="ExampleBean" 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 interface
Command command = createCommand();
// set the state on the (hopefully brand new) Command instance
command.setState(commandState);
return command.execute();
}
// okay... but where is the implementation of this method?
protected abstract Command createCommand();
}

<bean id="commandManager" class="fiona.apple.CommandManager">
<lookup-method name="createCommand" bean="command"/>
</bean>

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.