您的位置:首页 > 其它

Unable to proxy method HibernateDaoSupport.setHibernateTemplate because it is final

2014-05-14 23:24 731 查看
最近整合struts 1 + spring 2.5 + hibernate 3.2,demo调通后分析日志,发现控制台输出一系列警告:

警告: Unable to proxy method [public final org.springframework.orm.hibernate3.HibernateTemplate org.springframework.orm.hibernate3.support.HibernateDaoSupport.getHibernateTemplate()] because it is final:
All calls to this method via a proxy will be routed directly to the proxy.

2014-5-14 22:47:52 org.springframework.aop.framework.Cglib2AopProxy doValidateClass

解决方案:修改applicationContext.xml中spring事务控制机制,换一种实现方案。

报警告信息的配置:

<!-- 指定事务管理器类,将sessionFactory注入,让该事务管理器具有打开和关闭事务的能力 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 为事务管理器类指定匹配器,通过用name指定的匹配字符串进行对对应的方法进行打开和关闭事务 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="deploy*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 为事务管理器类指定进行匹配的范围,到指定的地方通过匹配器字符串进行筛选,对应上后为该方法打开和关闭事务 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="managerOperation" expression="execution(* com.xy6.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="managerOperation" />
</aop:config>
修改后的配置:

<bean id="myTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="myBaseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="myTransactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<!--
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="save">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="edit*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="disPlay*">PROPAGATION_REQUIRES_NEW</prop>
-->
</props>
</property>
</bean>
警告产生原因:org.springframework.orm.hibernate3.support.HibernateDaoSupport类中getHibernateTemplate等方法为final类型。

复制去Google翻译翻译结果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐