Spring @Controller 和事务管理器 [英] Spring @Controller and Transactionmanager
问题描述
我有一个基本的 Spring Controller
I'm having a basic 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/
测试哪个工作正常.
Tested via curl -X GET http://myIP:myPort/b/c/
Which works fine.
如果我通过
<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: ...
因此使用了事务配置.
The mapping is not working any longer. I get a 404 Error on client side an on Server the Method is not entered. Doing a JUnit test with a breakpoint in doCriticalStuff
I can see AopUtils.invokeJoinpointUsingReflection(Object, Method, Object[]) line: ...
so the transaction config is used.
但是映射不再起作用.有任何想法吗?
But the mapping is not working any longer. Any ideas?
我使用的是 Spring 3.0.2.RELEASE
I'm using Spring 3.0.2.RELEASE
推荐答案
使用 动态代理,它阻止 Spring MVC 访问目标类上的 @RequestMapping
注释.您可以使用 <aop:config proxy-target-class="true">
作为解决方法.
Transactional aspect is applied using dynamic proxy, and it prevents Spring MVC from accessing the @RequestMapping
annotations on the target class. You may use <aop:config proxy-target-class="true">
as a workaround.
Spring 团队表示,出于效率原因,他们不会修复此行为(请参阅 评论 SPR-5084)
Spring team says that they wouldn't fix this behaviour for efficiency reasons (see comment on SPR-5084)
这篇关于Spring @Controller 和事务管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!