spring框架对容器管理bean和容器本身提供了额外增强功能。
1、bean后处理器,不对外提供服务,负责为容器的目标Bean生成代理等。需要实现BeanPostProcessor接口,里面含有两个实现方法:postProcessBeforeInitialization(Object bean , String name) 和 postProcessAfterInitialization(Object bean , String name).其中bean是目标实例,name是目标实例的名字。如果用xmlbeanFactory来作为容器,需要手动注册Bean后处理器,但是applicationContext就会自动扫描。在现实中,根据bean名称自动代理就是运用Bean后处理器
2、容器后处理器。典型应用属性占位符、重写占位符配置器等。如下:
<context:property-placeholder location="WEB-INF/jdbc.properties,WEB-INF/mail.properties"/>
<!-- Local C3P0 DataSource that works in any environment -->
<!-- See JPetStore for an example of using Apache Commons DBCP as alternative -->
<!-- (Both DataSource implementations have a "close" method to be called on shutdown) -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
1、bean后处理器,不对外提供服务,负责为容器的目标Bean生成代理等。需要实现BeanPostProcessor接口,里面含有两个实现方法:postProcessBeforeInitialization(Object bean , String name) 和 postProcessAfterInitialization(Object bean , String name).其中bean是目标实例,name是目标实例的名字。如果用xmlbeanFactory来作为容器,需要手动注册Bean后处理器,但是applicationContext就会自动扫描。在现实中,根据bean名称自动代理就是运用Bean后处理器
2、容器后处理器。典型应用属性占位符、重写占位符配置器等。如下:
<context:property-placeholder location="WEB-INF/jdbc.properties,WEB-INF/mail.properties"/>
<!-- Local C3P0 DataSource that works in any environment -->
<!-- See JPetStore for an example of using Apache Commons DBCP as alternative -->
<!-- (Both DataSource implementations have a "close" method to be called on shutdown) -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>