<bean id="targetCommentsAutoReplyBiz" class="com.yododo.biz.micro.autoReply.impl.TargetCommentsAutoReplyBizImpl"> <property name="autoreplyContentReplaceMap"> <map> <entry key="areaname"> <bean class="com.yododo.biz.micro.autoReplyMode.impl.AreaNameReplaceBizImpl"></bean> </entry> </map> </property> </bean> <bean id="autoreplyLogBiz" class="com.yododo.biz.micro.impl.AutoreplyLogBizImpl"> <property name="autoReplyMap"> <map> <entry key="targetComments"> <ref bean="targetCommentsAutoReplyBiz"/> <bean class="com.yododo.biz.micro.autoReply.impl.TargetCommentsAutoReplyBizImpl"></bean> </entry> </map> </property> </bean>
原来代码如上,如此注入,在com.yododo.biz.micro.impl.AutoreplyLogBizImpl 的autoReplyMap中TargetCommentsAutoReplyBizImpl的autoreplyContentReplaceMap是为null的。
分析原因:在为autoreplyLogBiz注入autoReplyMap初始化autoReplyMap的时候,TargetCommentsAutoReplyBizImpl对象并没有从spring容器中获取,而是重新new一个对象,当然没有重新new TargetCommentsAutoReplyBizImpl中的autoreplyContentReplaceMap,所以。。。。
解决方法,如下配置:
<bean id="targetCommentsAutoReplyBiz" class="com.yododo.biz.micro.autoReply.impl.TargetCommentsAutoReplyBizImpl">
<property name="autoreplyContentReplaceMap">
<map>
<entry key="areaname">
<bean class="com.yododo.biz.micro.autoReplyMode.impl.AreaNameReplaceBizImpl"></bean>
</entry>
</map>
</property>
</bean>
<bean id="autoreplyLogBiz" class="com.yododo.biz.micro.impl.AutoreplyLogBizImpl">
<property name="autoReplyMap">
<map>
<entry key="targetComments">
<ref bean="targetCommentsAutoReplyBiz"/>
</entry>
</map>
</property>
</bean>