一、前言
基于spring-boot项目运行时,报出“java.lang.UnsupportedClassVersionError: javax/annotation/ManagedBean : Unsupported major.minor version 51.0”异常,详情日志如下
. ____ _ __ _ _@b@ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \@b@( ( )\___ | '_ | '_| | '_ \/ _' | \ \ \ \@b@ \\/ ___)| |_)| | | | | || (_| | ) ) ) )@b@ ' |____| .__|_| |_|_| |_\__, | / / / /@b@ =========|_|==============|___/=/_/_/_/@b@ :: Spring Boot :: (v1.5.6.RELEASE)@b@@b@2018-04-01 23:17:22.841 ERROR 5628 --- [ main] o.s.boot.SpringApplication : Application startup failed@b@@b@java.lang.UnsupportedClassVersionError: javax/annotation/ManagedBean : Unsupported major.minor version 51.0@b@ at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.6.0_39]@b@ at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) ~[na:1.6.0_39]@b@ at java.lang.ClassLoader.defineClass(ClassLoader.java:615) ~[na:1.6.0_39]@b@ at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) ~[na:1.6.0_39]@b@ at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) ~[na:1.6.0_39]@b@ at java.net.URLClassLoader.access$000(URLClassLoader.java:58) ~[na:1.6.0_39]@b@ at java.net.URLClassLoader$1.run(URLClassLoader.java:197) ~[na:1.6.0_39]@b@ at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_39]@b@ at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ~[na:1.6.0_39]@b@ at java.lang.ClassLoader.loadClass(ClassLoader.java:306) ~[na:1.6.0_39]@b@ at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) ~[na:1.6.0_39]@b@ at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[na:1.6.0_39]@b@ at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters(ClassPathScanningCandidateComponentProvider.java:188) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:164) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:138) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:111) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:83) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:62) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_39]@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_39]@b@ at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_39]@b@ at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_39]@b@ at java.lang.Class.newInstance0(Class.java:357) ~[na:1.6.0_39]@b@ at java.lang.Class.newInstance(Class.java:310) ~[na:1.6.0_39]@b@ at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:77) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]@b@ at org.springframework.boot.SpringApplication.createApplicationContext(SpringApplication.java:529) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]@b@ at org.springframework.boot.SpringApplication.run(SpringApplication.java:299) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]@b@ at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]@b@ at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]@b@ at cn.bocon.Application.main(Application.java:18) [classes/:na]
二、解决办法
1.右击项目,菜单选择“Run As”->"Run Configurations"项目,如下图
2.如下图在弹出窗口选择“Application”,再JRE的标签页将JRE调整为jdk1.8.0_11项
3.点击“Run”后,问题解决了,项目正常运行,正常日志如下
. ____ _ __ _ _@b@ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \@b@( ( )\___ | '_ | '_| | '_ \/ _' | \ \ \ \@b@ \\/ ___)| |_)| | | | | || (_| | ) ) ) )@b@ ' |____| .__|_| |_|_| |_\__, | / / / /@b@ =========|_|==============|___/=/_/_/_/@b@ :: Spring Boot :: (v1.5.6.RELEASE)@b@@b@2018-04-02 00:05:26.153 INFO 7960 --- [ main] com.xwood.Application : Starting Application on DESKTOP-PG6VEFD with PID 7960 (C:\WS\NJ\project\xwood-project\springboot-helloworld\target\classes started by nijun in C:\WS\NJ\project\xwood-project\springboot-helloworld)@b@2018-04-02 00:05:26.157 INFO 7960 --- [ main] com.xwood.Application : No active profile set, falling back to default profiles: default@b@2018-04-02 00:05:26.224 INFO 7960 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@d282e0: startup date [Mon Apr 02 00:05:26 CST 2018]; root of context hierarchy@b@2018-04-02 00:05:28.458 INFO 7960 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)@b@2018-04-02 00:05:28.470 INFO 7960 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]@b@2018-04-02 00:05:28.471 INFO 7960 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16@b@2018-04-02 00:05:28.603 INFO 7960 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext@b@2018-04-02 00:05:28.603 INFO 7960 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2383 ms@b@2018-04-02 00:05:28.837 INFO 7960 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]@b@2018-04-02 00:05:28.843 INFO 7960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]@b@2018-04-02 00:05:28.843 INFO 7960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]@b@2018-04-02 00:05:28.844 INFO 7960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]@b@2018-04-02 00:05:28.844 INFO 7960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]@b@2018-04-02 00:05:29.332 INFO 7960 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@d282e0: startup date [Mon Apr 02 00:05:26 CST 2018]; root of context hierarchy@b@2018-04-02 00:05:29.444 INFO 7960 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.xwood.web.HelloWorldController.sayHello()@b@2018-04-02 00:05:29.448 INFO 7960 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)@b@2018-04-02 00:05:29.449 INFO 7960 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)@b@2018-04-02 00:05:29.494 INFO 7960 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]@b@2018-04-02 00:05:29.494 INFO 7960 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]@b@2018-04-02 00:05:29.545 INFO 7960 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]@b@2018-04-02 00:05:29.731 INFO 7960 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup@b@2018-04-02 00:05:29.806 INFO 7960 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)@b@2018-04-02 00:05:29.810 INFO 7960 --- [ main] com.xwood.Application : Started Application in 4.074 seconds (JVM running for 4.568)