I have been debugging this for awhile now, and I'm hoping someone could shed some light here.
I have a Maven project that is added into Jenkins, using JDK 1.6. I'm using AOP in this project to handle the database transaction.
When I run the build in Jenkins, my testcase fails with the following exceptions:-
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]
...
...
The DataHandlerClassificationImpl
class looks something like this:-
@Service
public class DataHandlerClassificationImpl extends DataHandler {
@Resource(name="writerDataLocationImpl")
private WriterData writerData;
...
}
WriterData
is an interface with multiple implementations.
I am able to execute the code without problem from the IDE. To determine whether it is a Maven problem or Jenkins problem, I navigated to the Jenkins' project job folder using command line and I'm able to run mvn test
without any errors.
I know the proxy error has something to do with AOP, and that I can only autowire to an interface instead of a concrete class... but that's not the case here since I'm able to run my code fine outside Jenkins.
Any ideas? Thanks.
mvn
build command? Can you try replacing injected filed toprivate Object writerData
and dumpwriterData.getClass().getInterfaces
after dealing with compilation errors? This might give us a clue what is the nature of this unwanted and strange proxy. – Calendsclean cobertura:cobertura site
. Just for my curiosity sake, I changed it toclean test
and it worked fine. When I changed it toclean site
, I'm getting the same exception again. It looks like it has something to do withsite
. Any ideas? Thanks. – WaybillwriterData.getClass().getInterfaces
? Intellij basically gives me a regular compilation error. – Waybillmvn site
. I ran that command from the command line, and I'm getting the exact exception. I'm not sure why this is behaving differently fromtest
. – WaybillArrays.asList(new Object().getClass().getInterfaces())
withinafterPropertiesSet
or@PostConstruct
. I am a bit surprised thatsite
is causing this problem to appear as I know Cobertura/Sonar tend to introduce this bug. Can you trymvn cobertura:cobertura
alone? Should fail as well... – Calendssite
(reporting)? I'm pretty sure it's Cobertura's fault, notsite
. – Calendsmvn cobertura:cobertura test
and I get the exception. Yes, the reporting contains cobertura-maven-plugin (version 2.5.1). I'm going to try removing that to see if the problem goes away for now. – Waybill<aop:config proxy-target-class="true">
. If it works for you let me know, I will form an answer from these comments for future readers. Also try googling "cobertura spring proxy" - you'll find plenty people having the same issue. – Calends<aop:config proxy-target-class="true">
indeed fixed the problem! Thanks much. If you could post your last comment as an answer below, I'll upvote it and mark it as completed. Thanks again. – Waybill