1

In my applicationContext.xml file I have this error

Error occured processing XML 'foo/bar/annotations/SomeAnnotation : Unsupported major.minor version 52.0'. See Error Log for more details

on this line

<context:component-scan base-package="foo.bar" />

My STS is set to use Java 1.8 as the default JRE, this project has 1.8 JRE on its Java Build Path, my JAVA_HOME is pointing to jdk 1.8, and I have the maven-compiler-plugin set to use source and target 1.8.

Is the spring plugin using 1.6 somehow? Before this I was using 1.6, is there some setting I'm missing?


Update 2: I forgot that 52 meant it was compiled with Java 8, I thought it meant 7. That explains why I was wondering what was set to 6 instead of 7.


Update: Here are the contents of the error log.

!ENTRY org.springframework.ide.eclipse.beans.core 1 0 2015-11-24 15:11:08.176
!MESSAGE Error occured processing '/foo-engine/src/main/resources/applicationContext.xml'
!STACK 0
java.lang.UnsupportedClassVersionError: foo/bar/annotations/SomeAnnotation : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(RecursiveAnnotationAttributesVisitor.java:47)
    at org.springframework.asm.ClassReader.readAnnotationValues(ClassReader.java:1802)
    at org.springframework.asm.ClassReader.accept(ClassReader.java:642)
    at org.springframework.asm.ClassReader.accept(ClassReader.java:508)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:64)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:279)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:248)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:87)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
    at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1428)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:168)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1357)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:410)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:394)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:453)
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

!ENTRY org.springframework.ide.eclipse.core 4 2 2015-11-24 15:11:08.423
!MESSAGE Problems occurred when invoking code from plug-in: "org.springframework.ide.eclipse.core".
!STACK 0
java.lang.UnsupportedClassVersionError:foo/baz/repository/BazRepository : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.springframework.ide.eclipse.data.jdt.core.RepositoryInformation.<init>(RepositoryInformation.java:88)
    at org.springframework.ide.eclipse.data.internal.validation.InvalidDerivedQueryRule.supports(InvalidDerivedQueryRule.java:71)
    at org.springframework.ide.eclipse.data.internal.validation.InvalidDerivedQueryRule.supports(InvalidDerivedQueryRule.java:44)
    at org.springframework.ide.eclipse.core.model.validation.AbstractValidator$ValidationVisitor.visit(AbstractValidator.java:278)
    at org.springframework.ide.eclipse.core.model.AbstractModelElement.accept(AbstractModelElement.java:131)
    at org.springframework.ide.eclipse.core.model.validation.AbstractValidator.validate(AbstractValidator.java:142)
    at org.springframework.ide.eclipse.core.model.validation.AbstractValidator.validate(AbstractValidator.java:104)
    at org.springframework.ide.eclipse.core.internal.project.SpringProjectContributionManager$7.execute(SpringProjectContributionManager.java:260)
    at org.springframework.ide.eclipse.core.internal.project.SpringProjectContributionManager$9.run(SpringProjectContributionManager.java:291)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.springframework.ide.eclipse.core.internal.project.SpringProjectContributionManager.execute(SpringProjectContributionManager.java:294)
    at org.springframework.ide.eclipse.core.internal.project.SpringProjectContributionManager.runValidator(SpringProjectContributionManager.java:257)
    at org.springframework.ide.eclipse.core.internal.project.SpringProjectContributionManager.build(SpringProjectContributionManager.java:131)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Captain Man
  • 6,997
  • 6
  • 48
  • 74
  • I believe this old post will be useful for you http://stackoverflow.com/questions/24790834/cant-fix-unsupported-major-minor-version-52-0-even-after-fixing-compatibility/24791708?noredirect=1#comment38477851_24791708 – Facepalmed Nov 24 '15 at 17:10
  • When exactly do you get this error? By executing what task? – Zilvinas Nov 24 '15 at 17:54
  • @Zilvinas when the project builds. I delete the error and then clean it or do a maven refresh and it comes back. – Captain Man Nov 24 '15 at 17:56
  • Well clearly your compiler is using java v 7 or older. If your maven compiler is configured to java 8, then try to update project maven settings. – Zilvinas Nov 24 '15 at 18:21
  • @Zilvinas My class files *did* have 52 as the major version (checked with javap). I just can't figure out what is set to java 6 to have the issue with major version 52. I'll try to update the configuration again. I did try deleting all the eclipse files and reimporting (.settings, .eclipse, .project, .springBeans) – Captain Man Nov 24 '15 at 18:24
  • @CaptainMan I meant that your eclipse compiler uses java v < 8 – Zilvinas Nov 24 '15 at 18:28
  • @Zilvinas The project's compiler's "compliance" level was at 1.8, but changing the workspace's from 1.6 to 1.8 seems to have fixed the problem. – Captain Man Nov 24 '15 at 19:17
  • @Zilvinas Nevermind, after reopening the issue seems to have returned. – Captain Man Nov 24 '15 at 19:48

4 Answers4

2

It looks like you are running STS itself on an older JDK or JRE than 1.8. Since the Spring support under the hood needs some kind of classloading and class analysis, it can't do that for Java8 compiled classes of your project if it itself runs with JDK7 or previous versions.

Martin Lippert
  • 5,988
  • 1
  • 15
  • 18
2

First of all, the first entry of either stack trace points to the method java.lang.ClassLoader.defineClass1 which is a native method invoking the JVM specific class loading mechanism. If this method fails due to an unsupported class version number, you are running on a JVM incapable of loading such classes and no runtime option could change that.

To verify the version, I picked the following lines from your stack trace:

at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

which indicate that in the JRE source code, the line 1145 of ThreadPoolExecutor.java must be inside the method runWorker and holding the invocation of the run method of a task.

Checking the source code of 6b14, 6b27 and even an earlier version of Java 7 (7-b147) we find the line 1145 being even outside the method runWorker, but with 7u40-b43 we find a match, the line 1145 being within runWorker and bearing the invocation of the run() method of a task. Thus, we can conclude that this code is not running under Java 6, it’s running in a Java 7 implementation being newer than 7-b147 and not being capable of loading Java 8 classes.

As an additional indicator, the implementation of ThreadPoolExecutor.java has changed again in Java 8 and the line 1145 doesn’t match the run() invocation anymore.

Now that you know that this failing code is running neither on your old Java 6 nor the newly installed Java 8, but a Java 7 implementation that must be lying somewhere in your system, you may search where it comes from and how to replace it…

Holger
  • 285,553
  • 42
  • 434
  • 765
  • I am away from my computer at the moment but am 99% sure that java 7 is on the PATH (8 is JAVA_HOME though), so this is most likely the issue. – Captain Man Nov 25 '15 at 16:25
2

As Martin and a few others have already diagnosed, the problem is not what your workspace JRE is pointing to, but that you are running STS itself on a Java 7 JVM. Because of the way STS creates its 'beans model' for your project, classes from the project's classpath are being classloaded by STS and so it can't do that when running on JVM 1.7 if the classes have been compiled for Java 1.8.

What none of the other answers have mentioned, however, is how you can make sure that STS is running on the JVM you want it to. Here is how:

Open the STS.ini file, it should be right next to the STS.exe you use to launch STS. Add (or change if they are already there) two lines to the front of the file like so:

-vm
...path the javaw.exe of the JVM you want to use...

It is important these two arguments are on separate lines.

If you do not put this argument then the eclipse launcher will try to find a JVM on its own and exactly how it does that is a bit of 'dark magic'. So its best to set it explicitly in your .ini file if you need STS run on a specific VM.

Kris
  • 3,898
  • 1
  • 23
  • 32
-1

Please check your installed JREs in your eclipse, and which one is set to default.

Installed JREs

Zilvinas
  • 5,518
  • 3
  • 26
  • 26