小编典典

Spring @Controller和Transactionmanager

spring-mvc

我有一个基本的Spring Controller

package org.foo;

@Controller
public class HelloWorldController implements IHelloWorldController
{
   @RequestMapping(value = "/b/c/", method = RequestMethod.GET)
   public void doCriticalStuff(HttpServletRequest request, HttpServletResponse response){
      //...
   }
}

经过测试,curl -X GET http://myIP:myPort/b/c/ 可以正常工作。

如果我通过配置事务管理

<bean id="txManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <tx:method name="*" />
    </tx:attributes>
</tx:advice>
<aop:config>
    <aop:pointcut id="helloWorldPC"
        expression="execution(* org.foo.IHelloWorldController.*(..)) &amp;&amp; !execution(* java.lang.Object.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="helloWorldPC" />
</aop:config>

映射不再起作用。我在客户端收到404错误,并且在服务器上未输入方法。doCriticalStuff我可以看到使用断点进行JUnit测试,AopUtils.invokeJoinpointUsingReflection(Object, Method, Object[]) line: ...因此可以使用事务配置。

但是映射不再起作用。有任何想法吗?

我正在使用Spring 3.0.2.RELEASE


阅读 313

收藏
2020-06-01

共1个答案

小编典典

事务方面是使用动态代理来应用的,它可以防止Spring
MVC访问@RequestMapping目标类上的注释。您可以将其<aop:config proxy-target- class="true">用作解决方法。

Spring团队表示,出于效率考虑,他们不会解决此问题(请参阅对SPR-5084的评论

2020-06-01