lim*_*imc 19 junit spring unit-testing hudson jenkins
我现在已经调试了一段时间了,我希望有人能在这里说清楚.
我有一个使用JDK 1.6添加到Jenkins的Maven项目.我在这个项目中使用AOP来处理数据库事务.
当我在Jenkins中运行构建时,我的测试用例失败,但有以下例外: -
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataHandlerClassificationImpl':
Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'writerDataLocationImpl' must be of type [xxx.script.WriterData],
but was actually of type [$Proxy17]
...
...
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'writerDataLocationImpl' must be of type [xxx.script.WriterData],
but was actually of type [$Proxy17]
...
...
Run Code Online (Sandbox Code Playgroud)
该DataHandlerClassificationImpl
课程看起来像这样: -
@Service
public class DataHandlerClassificationImpl extends DataHandler {
@Resource(name="writerDataLocationImpl")
private WriterData writerData;
...
}
Run Code Online (Sandbox Code Playgroud)
WriterData
是一个具有多个实现的接口.
我能够在没有问题的情况下从IDE执行代码.为了确定它是Maven问题还是Jenkins问题,我使用命令行导航到Jenkins的项目作业文件夹,我能够毫无错误地运行mvn test
.
我知道代理错误与AOP有关,而且我只能自动连接到一个接口而不是一个具体的类......但事实并非如此,因为我能够在Jenkins之外运行我的代码.
有任何想法吗?谢谢.
Tom*_*icz 43
摘自上述问题评论:
你在Jenkins上运行Cobertura,Sonar或其他代码工具吗?请注意,mvn site
也可能配置为包括生成的Cobertura报告site
.
Cobertura的问题在于它执行相当繁重的字节码检测,包括添加一些自定义接口.当Spring启动时,它会为bean生成代理.如果bean至少有一个接口,则它使用标准Java代理.否则它会尝试创建基于类的代理.
我想在你的情况下使用CGLIB类代理,但在Cobertura工具之后,Spring回归到java代理.这导致启动错误,因为依赖注入期望类(或CGLIB子类).
简而言之,强制CGLIB类代理,你会没事的:
<aop:config proxy-target-class="true"/>
Run Code Online (Sandbox Code Playgroud)