我有一个基本的 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.*(..)) && !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/