2010-06-24 197 views
1

我有一個基本的春天控制器春@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: ...,因此使用事務配置。

但映射不再有效。有任何想法嗎?

我使用彈簧3.0.2.RELEASE

回答

4

事務方面是使用dynamic proxy應用,並且它可以防止彈簧MVC訪問目標類中的@RequestMapping註釋。您可以使用<aop:config proxy-target-class="true">作爲解決方法。

Spring團隊說,他們不會解決這個問題出於效率的考慮(見comment on SPR-5084

+0

好吧,我寫了補充而不是和包括CGLIB版本2.2現在我得到「由於缺少行號屬性而無法安裝斷點」嘗試http://solveme.wordpress.com/2008/08/27/unable-to-install-breakpoint-due-to-missing-line-數字屬性/目前沒有幫助。我正在使用m2Eclipse版本0.10.0.20100209-0800也許這是一個問題? – 2010-06-25 06:52:18

+0

除了斷點消息我看到以下調用堆棧 MethodProxy.invoke(對象,對象[]) Cglib2AopProxy $ CglibMethodInvocation.invokeJoinpoint()\t Cglib2AopProxy $ CglibMethodInvocation(ReflectiveMethodInvocation).proceed()\t TransactionInterceptor.invoke(的MethodInvocation ) Cglib2AopProxy $ CglibMethodInvocation(ReflectiveMethodInvocation).proceed()\t ExposeInvocationInterceptor.invoke(的MethodInvocation) Cglib2AopProxy $ CglibMethodInvocation(ReflectiveMethodInvocation).proceed() Cglib2AopProxy $ DynamicAdvisedInterceptor.intercept(對象,方法,對象[],MethodProxy) 代理使用AOP代理 – 2010-06-25 07:24:15