`

迷信Spring

阅读更多
说来也怪,我使用相同的程序代码来做应用,因为基本模板已经定义,所以所有的工作几乎就是COPY和PASTE,但是就是这样做,也发现了一个Spring的一个漏洞。如下解说:
原来的注入XML
----------------------------------------------------------------------
..................................
<bean id="mssqltransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

<bean id="mssqlObjectDao" class="com.throuhout.j2eemodel.spring.service.dao.hibernate.MssqlHibernateDao">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>


<!-- Service -->
<!-- mssqlObjManager -->
<bean id="mssqlObjectManagerTarget" class="com.throuhout.j2eemodel.spring.service.MssqlManagerImpl">
<property name="mssqlObjectDao">
<ref local="mssqlObjectDao" />
</property>
</bean>

<bean id="mssqlObjectManager" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="mssqltransactionManager" />
</property>

<property name="target">
<ref local="mssqlObjectManagerTarget" />
</property>

<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
</beans>
------------------------------------------------------------------
JAVA文件。
------------------------------------------------------------------
public void setMssqlObjectDao(IMssqlObjectDao mssqlObjectDao) {
dao = mssqlObjectDao;
}
------------------------------------------------------------------
以上的不能够成功运行,在依赖注入生成BEAN时发生错误,为什么呀?

就是这个关键字mssqlObjectDao、mssqlObjectManager、mssqlObjectManagerTarget的错误,因为你的Dao前面的字符有大小写的缘故,就测试不能够通过。
呵呵,不瞞大家说,我在JAVAEYE上提出这个问题,还被ROBBIN删除了,自力更生,呀呀,终于达到解决。
如下是正确的代码。
--------------------------------------------------------------------
<bean id="mysqltransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mysqlSessionFactory" />
</property>
</bean>

<bean id="mssqltransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mssqlSessionFactory" />
</property>
</bean>


<bean id="userDao" class="com.throuhout.j2eemodel.spring.service.dao.hibernate.UserHibernateDao">
<property name="sessionFactory">
<ref local="mysqlSessionFactory" />
</property>
</bean>

<bean id="mssqlDao" class="com.throuhout.j2eemodel.spring.service.dao.hibernate.MssqlHibernateDao">
<property name="sessionFactory">
<ref local="mssqlSessionFactory" />
</property>
</bean>


<!-- Service -->
<!-- userManager -->

<bean id="userManagerTarget" class="com.throuhout.j2eemodel.spring.service.UserManagerImpl">
<property name="userDao">
<ref local="userDao" />
</property>
</bean>

<bean id="userManager" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="mysqltransactionManager" />
</property>

<property name="target">
<ref local="userManagerTarget" />
</property>

<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>

<!-- mssqlObjManager -->
<bean id="mssqlManagerTarget" class="com.throuhout.j2eemodel.spring.service.MssqlManagerImpl">
<property name="mssqlDao">
<ref local="mssqlDao" />
</property>
</bean>

<bean id="mssqlManager" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="mssqltransactionManager" />
</property>

<property name="target">
<ref local="mssqlManagerTarget" />
</property>

<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>

-------------------------------------------------------------------
public void setMssqlDao(IMssqlObjectDao mssqlDao) {
dao = mssqlDao;
}
-----------------------------------------------------------------
欢迎大家互相交流,互相学习。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics