一、问题现象
运行项目时报错"Unsupported major.minor version 51.0",因为jdk版本引起的编译异常问题
[xx][ERROR] [2015-10-25 10:47:35] org.springframework.web.context.ContextLoader.initWebApplicationContext(331) | Context initialization failed@b@org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.xx.xx.rpc.service.ISessionManager': Cannot resolve reference to bean 'sessionService' while setting bean property 'ref'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.xx.xx.rpc.service.SessionManager] for bean with name 'sessionService' defined in file [C:NJJSPACECVP_BSS argetclassesspring-dubbo.xml]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: com/ekache/bss/rpc/service/SessionManager : Unsupported major.minor version 51.0@b@ at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)@b@ at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)@b@ at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)@b@ at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)@b@ at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)@b@ at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)@b@ at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)@b@ at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)@b@ at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)@b@ at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)@b@ at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)@b@ at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)@b@ at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)@b@ at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)@b@ at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)@b@ at org.apache.catalina.startup.Embedded.start(Embedded.java:825)@b@ at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)@b@ at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)@b@ at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)@b@ at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)@b@ at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)@b@ at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)@b@ at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)@b@ at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)@b@ at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)@b@ at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)@b@ at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)@b@ at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)@b@ at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)@b@ at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)@b@ at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)@b@ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)@b@ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)@b@ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)@b@ at java.lang.reflect.Method.invoke(Method.java:597)@b@ at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)@b@ at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)@b@ at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)@b@ at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)@b@Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.xx.xx.rpc.service.SessionManager] for bean with name 'sessionService' defined in file [C:NJJSPACECVP_BSS argetclassesspring-dubbo.xml]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: com/xx/xx/rpc/service/SessionManager : Unsupported major.minor version 51.0@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1331)@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:453)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)@b@ at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)@b@ at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)@b@ ... 45 more@b@Caused by: java.lang.UnsupportedClassVersionError: com/xx/xx/rpc/service/SessionManager : Unsupported major.minor version 51.0@b@ at java.lang.ClassLoader.defineClass1(Native Method)@b@ at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)@b@ at java.lang.ClassLoader.defineClass(ClassLoader.java:615)@b@ at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)@b@ at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)@b@ at java.net.URLClassLoader.access$000(URLClassLoader.java:58)@b@ at java.net.URLClassLoader$1.run(URLClassLoader.java:197)@b@ at java.security.AccessController.doPrivileged(Native Method)@b@ at java.net.URLClassLoader.findClass(URLClassLoader.java:190)@b@ at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1141)@b@ at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)@b@ at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)@b@ at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)@b@ at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)@b@ ... 51 more
二、解决步骤
1. 右击项目,点击菜单中"Properties"项,选择“Java Compiler”,并选择版本1.6
2. 再选择“Java Build Path” - 点击“Libraries”tab页,并点击“Add Library”添加"jre6"库
3. 点击"Finish",然后点击"OK",这样问题就解决了