init-method 与afterPropertiesSet

init-method 与afterPropertiesSet 都是在初始化bean的时候执行,执行顺序是afterPropertiesSet 先执行,init-method 后执行,afterPropertiesSet 必须实现 InitializingBean接口 
今天遇到一问题,在配置文件中配置了init-method 
<bean id="financeAgent" class="com.sumavision.ecommerce.plateform.core.monitor.FinanceAgent" 
init-method="initialize" destroy-method="destroy"> 
<property name="jmsTemplate" ref="jmsTemplate" /> 
<property name="serviceMap"> 
<map 
value-type="com.sumavision.ecommerce.plateform.core.monitor.FinanceMonitorService"> 
<entry key="financeManageService" 
value-ref="financeManageService" /> 
<entry key="financeTransactService" 
value-ref="financeTransactService" /> 
</map> 
</property> 
</bean> 

<!-- Jndi --> 
<bean id="jndiTemplate" 
class="org.springframework.jndi.JndiTemplate"> 
<property name="environment"> 
<props> 
<prop key="java.naming.factory.initial"> 
weblogic.jndi.WLInitialContextFactory 
</prop> 
<prop key="java.naming.provider.url"> 
t3://192.166.68.44:7001 
</prop> 
<prop key="java.naming.factory.url.pkgs"> 
weblogic.jndi.factories 
</prop> 
</props> 
</property> 
</bean> 

<!-- jms sender --> 
<bean id="jmsConnectionFactory" 
class="org.springframework.jndi.JndiObjectFactoryBean"> 
<property name="jndiTemplate" ref="jndiTemplate" /> 
<property name="jndiName" value="ConnectionFactory" /> 
</bean> 
<bean id="jmsQueue" 
class="org.springframework.jndi.JndiObjectFactoryBean"> 
<property name="jndiTemplate" ref="jndiTemplate"></property> 
<property name="jndiName" value="Queue"></property> 
</bean> 

<!-- jms template --> 
<bean id="jmsTemplate" 
class="org.springframework.jms.core.JmsTemplate"> 
<property name="connectionFactory" ref="jmsConnectionFactory"></property> 
<property name="defaultDestination" ref="jmsQueue"></property> 
</bean>

在加载的时候不能执行,找了半天最后发现是因为

<beans default-lazy-init="true"></beans> 配置了延迟初始化,但是有的bean的init-method是可以运行的,具体需要再看下这个

<bean id="tradeAuditService"
  class="com.sumavision.ecommerce.plateform.core.audit.impl.TradeAuditServiceImpl"
  init-method="initialize">
  <property name="auditRuleDAO" ref="AuditRuleDAO"></property>
  <property name="negativelyTradeDAO" ref="NegativelyTradeDAO"></property>
  <property name="securityServiceManager"
   ref="securityServiceManager">
  </property>
 </bean>
 <bean id="tradeAuditServiceProxy" parent="baseTransactionProxy">
  <property name="target" ref="tradeAuditService"></property>
  <property name="transactionAttributes">
   <props>
    <prop key="process">
     PROPAGATION_REQUIRED,ISOLATION_SERIALIZABLE
    </prop>
   </props>
  </property>
 </bean>

这个就起作用了,

你可能感兴趣的:(init-method 与afterPropertiesSet)