Spring concept

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:

  1. define a bean first <bean name="xx" class="xx"/>
  2. 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.

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值