4

I am new to Spring, and I need to get a project to run successfully with Eclipse on JDK7. The project was previously running on JDK6.

I have all the source files, and jars that belonged to the original project in place. But when I try to run it, I get the following exception:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\Users\e\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\DMControl\WEB-INF\classes\com\...\...\...\MyClass.class]; nested exception is java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor

The only clue I have is that the first time I tried to run this, I got an error saying that I don't have the

org.springframework.core.io.support.SpringFactoriesLoader. 

I looked in my spring-core-3.1.2.RELEASE.jar and indeed the SpringFactoriesLoader wasn't there. Checking the current release, I found out that the missing class is indeed in the spring-core-3.2.2.RELEASE.jar.

So I changed the spring jars to the latest version. But now I get the exception in the title of this question.

Any idea?

The full stacktrace:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\Users\e\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\FTAdControl\WEB-INF\classes\com\fashiontraffic\adcontrol\health\restwebservices\HealthWSImpl.class]; nested exception is java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:242)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1190)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:63)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:257)
... 38 more
Eddy
  • 3,533
  • 13
  • 59
  • 89
  • Read : http://stackoverflow.com/questions/1980452/what-causes-java-lang-incompatibleclasschangeerror Clean and build. Or get the spring libs again remove everything from the class-path properly add them and try again. – Thihara Mar 17 '13 at 16:25
  • I forgot to explicitly tell you, get all the dependencies of the spring libraries and make sure they are the proper versions for that spring release. – Thihara Mar 17 '13 at 16:32
  • Thanks, Thihara, but cleaning and building doesn't do it. And I have about 50 other related jars in my lib, so I guess I need to know which one can be effected by the actual AnnotationMetadataReadingVisitor being changed. – Eddy Mar 17 '13 at 17:02
  • You changed the entire spring library, so you should change the dependencies accordingly otherwise the said error may occur... You can get the dependent binary distribution and try changing the libraries in there only.. That's around 6 i think... – Thihara Mar 18 '13 at 04:23
  • Do you where can I find the list of these? The ones in the list that can be found in the link you gave me above is already in my classpath. And from the exception it looks like I may have 2 versions of the AnnotationMetadataReadingVisitor class? – Eddy Mar 18 '13 at 07:50
  • You mean because of the / separations in the Spring class file? Try the spring website's download section. – Thihara Mar 18 '13 at 08:14
  • Looks like a library dependency version issue. Now do you understand? – Dave Newton Mar 19 '13 at 11:42
  • Thanks @DaveNewton, absolutely. This is exactly the example I needed in order to get it. I guess some people have to suffer before they realize a problem solving machine :) What I didn't understand (in our other thread) is that Maven is not just another annoying config file, but it's actually smart enough to go and resolve AND get the dependencies. Very cool. – Eddy Mar 19 '13 at 13:09
  • The other thread Dave and I refer to is here. http://stackoverflow.com/questions/15452874/maven-vs-eclipse – Eddy Mar 19 '13 at 13:10
  • @Eddy I think it's almost always that way--you don't know there's a problem until you know there's a problem. Maven does a lot more than dependency management, too. When it works, it's awesome. When it doesn't... intensely frustrating. – Dave Newton Mar 19 '13 at 13:32

4 Answers4

10

@Eddy, it sounds like you have jars from Spring 3.1 and 3.2 on your classpath, which isn't always bad but sometimes they don't play nicely together.

I had the same error on my Spring 3.2.2 project when I added spring-hateoas 0.4 which pulled in spring-webmvc 3.1.x and all of it's Spring 3.1 dependencies.

I excluded the Spring 3.1 dependencies, and all was well. Hope that helps.

SGT Grumpy Pants
  • 4,118
  • 4
  • 42
  • 64
  • Thanks @10gritSandpaper. I already went back to the previous version of Spring and it worked for me. – Eddy Apr 06 '13 at 15:17
  • 1
    On behalf of [amirhd](http://stackoverflow.com/users/2210206/amirhd): Make sure run a maven clean before redeploying the solution. – artless noise Jun 02 '13 at 17:26
3

This is due to the incompatible of the version of the jars. You can find more details at this blog.

0
<org.springframework-version>**4.2.1.RELEASE**</org.springframework-version> 

change the release version to the latest in the pom.xml (properties attribute)

then reference that property in all your springframework dependencies.

this is what worked for me!!

Farai
  • 180
  • 2
  • 12
0

In my case the problem was because I was using activemq-all library that contains an old Spring version (currently I'm using Spring 4.2.4.RELEASE) so I changed it with activemq-core library and the problem was solved.

Alexis Gamarra
  • 4,362
  • 1
  • 33
  • 23