Spring IOC container can be accessed via two ways
1. BeanFactory - a simple factory to access bean
2. Applicationcontext - it has beanfactory functions + extra: message, internationalize, etc.
Bean creation
1. standard way: <bean name="xx" class="xxx"/>
2. static factory method: <bean name="xx" class="xx" factory-method="xxx"/>
3. instance method:
- define a bean first <bean name="xx" class="xx"/>
- use the bean's factory method: <bean name="x2" factory-bean="xx" factory-method="mm" />
Bean reference :ref has a few properties
1. <ref bean="xxx"/>, current xml or same beanFacotry
2. <ref local="xxxx"/> only in same xml file
3. <ref parent="xxx"/> its dependent's bean definition
Spring init-method, destroy-method only used singleton , not prototype which is managed by application
in order to use {jdbc.url} in configure file, you need configure PropertyPlaceHolderConfigurer in the xml file
ApplicationContext vs SessionFactory
1. javaBean wont be constrcuted in sessionFactory
2. ApplicationContext will initialize all the beans
In web application, ContextLoaderServlet and ContextLoaderListener will load spring configure
use PropertyEditorRegistery to registery customized PropertyEditor
Way to use jndi
1. use JndiObjectFactoryBean (need setup jndi.properties, or setup jndiTemplate)
2. use jndiObjectTargetSource and proxyFactoryBean
PropertyOverrideConfigurer vs PropertyPlaceholderConfigurer
1. PropertyPlaceHolderConfigure, will configure like this
property file: key=value
xml file usage: {key}
2. PropertyOverrideConfigure will configure like this
property file: beanName.propertyName = XXxx
xml file: <bean name="beanName"><property name="propertyName">value</property></bean>
3. If propertyPlaceHolderConfigurer cannot find key, value pair, it will throw exception.
4. PropertyOverrideConfigurer will use default value if key/value pair can not be found.