ely*_*ion 12 spring instrumentation cobertura autowired maven
Cobertura仪器在特定情况下打破弹簧自动装配.有谁知道如何解决这个问题?
尝试在myService中自动装配myExecutor的已检测版本时,自动装配失败.在添加MyHappyExecutor和MySadExecutor之前,此工作正常.MyHappyExecutor和MySadExecutor是自动装配的,并且仅在MyExecutor中使用.
我已经附加了下面的异常输出.请注意,类和包名称已被编辑.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myService': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mycompany.executor.MyExecutor com.mycompany.service.impl.MyServiceImpl.myExecutor;
nested exception is java.lang.IllegalArgumentException: Can not set com.mycompany.executor.MyExecutor field com.mycompany.service.impl.MyServiceImpl.myExecutor to $Proxy20
Run Code Online (Sandbox Code Playgroud)
Cobertura仪表过程中的某些东西会影响Springs的自动装配.
强制CGLIB类代理将错误类型更改为"java.lang.NoClassDefFoundError"错误.这会影响标准测试目标以及Cobertura目标.
<aop:config proxy-target-class="true"/>
Run Code Online (Sandbox Code Playgroud)
以下是有关3个类的弹簧启动过程的输出.
2012-11-01 16:21:51 INFO [main] Overriding bean definition for bean 'myExecutor': replacing [Generic bean: class [com.mycompany.executor.MyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] with [Generic bean: class [com.mycompany.executor.MyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] - (DefaultListableBeanFactory.java:623)
2012-11-01 16:21:51 INFO [main] Overriding bean definition for bean 'happyExecutor': replacing [Generic bean: class [com.mycompany.executor.HappyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] with [Generic bean: class [com.mycompany.executor.HappyExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] - (DefaultListableBeanFactory.java:623)
2012-11-01 16:21:51 INFO [main] Overriding bean definition for bean 'sadExecutor': replacing [Generic bean: class [com.mycompany.executor.SadExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] with [Generic bean: class [com.mycompany.executor.SadExecutor]; scope=; abstract=false; lazyInit=false; autowireMode=1; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [configuration.xml]] - (DefaultListableBeanFactory.java:623)
Run Code Online (Sandbox Code Playgroud)
对于您的测试,您需要设置proxyTargetClass=true
@EnableTransactionManagement(mode=AdviceMode.ASPECTJ, proxyTargetClass=true)
Run Code Online (Sandbox Code Playgroud)
如果这适用于您的测试,但当您运行应用程序时它失败,那么您需要为测试和应用程序进行单独的配置。测试配置集proxyTargetClass=true和应用程序配置集proxyTargetClass=false
对于您的NoClassDefFoundError错误,我们需要查看堆栈跟踪。您可能还没有包含 spring-aop 库
| 归档时间: |
|
| 查看次数: |
2715 次 |
| 最近记录: |