java - Spring @Controller 和 Transactionmanager

标签 java spring transactions 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

最佳答案

事务方面使用 dynamic proxy 应用,它会阻止 Spring MVC 访问 @RequestMapping目标类的注解。您可以使用 <aop:config proxy-target-class="true">作为解决方法。

Spring 团队表示出于效率原因他们不会修复此行为(参见 comment on SPR-5084)

关于java - Spring @Controller 和 Transactionmanager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3111698/

相关文章:

java - 停止该方法直到另一个执行完成?

java - 使用 Spring/EHCache 在负载下刷新缓存

java - spring工具套件创建可运行的jar错误查找配置文件

mysql - 为什么 MySQL (MariaDB) 更新事务返回 '0 row affected' ?

java - 如何打破设计中的循环依赖

java - 一维数组和多维数组的 array.clone() 的不同输出

spring - 为什么 Spring Social facebook -2.0.3 使用已弃用的图 api 版本 2.5(已弃用)

java - 带有延迟加载的 MVC

java - 事件观察者方法调用服务方法?

java - 使用 Ruby 与 jRuby 的设计问题