0

I have a project which is working locally, but when I try to deploy it to a tomcat 7 server, it gets the following exception:

ERROR: [Feb-05 16:39:30,240] web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.CategoryController] for bean with name 'categoryController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/CategoryController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/CategoryController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.CategoryController)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.CategoryController] for bean with name 'categoryController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/CategoryController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/CategoryController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.CategoryController)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.CheopsController] for bean with name 'cheopsController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/CheopsController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/CheopsController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.CheopsController)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.StatusController] for bean with name 'statusController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/StatusController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/StatusController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.StatusController)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.SurveyController] for bean with name 'surveyController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/SurveyController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/SurveyController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.SurveyController)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.ThresholdController] for bean with name 'thresholdController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/ThresholdController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/ThresholdController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.ThresholdController)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.services.impl.CategoryServiceImpl] for bean with name 'categoryServiceImpl' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/services/impl/CategoryServiceImpl.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/services/impl/CategoryServiceImpl : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.services.impl.CategoryServiceImpl)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.services.impl.CheopsServiceImpl] for bean with name 'cheopsServiceImpl' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/services/impl/CheopsServiceImpl.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/services/impl/CheopsServiceImpl : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.services.impl.CheopsServiceImpl)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.services.impl.StatusServiceImpl] for bean with name 'statusServiceImpl' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/services/impl/StatusServiceImpl.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/services/impl/StatusServiceImpl : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.services.impl.StatusServiceImpl)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.services.impl.ThresholdServiceImpl] for bean with name 'thresholdServiceImpl' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/services/impl/ThresholdServiceImpl.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/services/impl/ThresholdServiceImpl : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.services.impl.ThresholdServiceImpl)
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.services.SurveyService] for bean with name 'surveyService' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/services/SurveyService.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/services/SurveyService : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.services.SurveyService)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:525)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1359)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
    at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1500)
    at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:252)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.CategoryController] for bean with name 'categoryController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/CategoryController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/CategoryController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.CategoryController)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1330)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:385)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:362)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:348)
    at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1051)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:119)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:103)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:126)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    ... 45 more
Caused by: java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/CategoryController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.CategoryController)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2737)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1124)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:247)
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)
    ... 56 more
Related cause:
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [se.kth.example-project.webservices.rest.CategoryController] for bean with name 'categoryController' defined in file [/proj/webdocs/test-project/root/example-project/WEB-INF/classes/se/kth/example-project/webservices/rest/CategoryController.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: se/kth/example-project/webservices/rest/CategoryController : Unsupported major.minor version 52.0 (unable to load class se.kth.example-project.webservices.rest.CategoryController)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1330)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)

What is the cause of this? I haven't edited anything.. It works locally, but not deployed...

EDIT 1

Added full stacktrace

EDIT 2

This is not a version mismatch error, since I've changed the tomcat version on my IDE to 6.0 (which is also the tomcat version on the server that I'm trying to deploy to). Please help..

benskiiii
  • 439
  • 3
  • 11
  • 23
  • It's possible that you compile your code using Java 8 and now you are trying to run it on Java 7? – Leandro Carracedo Feb 05 '15 at 15:58
  • possible duplicate of [Unsupported major.minor version 51.0](http://stackoverflow.com/questions/10382929/unsupported-major-minor-version-51-0) – gknicker Feb 05 '15 at 16:04
  • try installing jdk 7 in your local and then rebuild your project with jdk7 or install jdk8 in your tomcat server.. I guess first option is easier to implement :) If you're using maven for building ur project, just set the target version to 1.7 in `maven-compiler-plugin`.. no need to install jdk7 :) – Arkantos Feb 05 '15 at 17:41
  • sorry i shouldn't be asking to install jdk7 blindly. check the `java -version` of your tomcat server. In your local, rebuild your project with same jdk version. – Arkantos Feb 05 '15 at 17:50

2 Answers2

2

This indicates class incompatibility. You should make sure the client has the same versions of the classes as the server. If you do a Google search for "unsupported major minor version" or "Java unsupported major minor version", you'll get a lot of hits (from SO too).

See also:

How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

Community
  • 1
  • 1
peter.petrov
  • 38,363
  • 16
  • 94
  • 159
2

You have some classloading issues. java.lang.UnsupportedClassVersionError is reported for class se.kth.webservices.rest.CategoryController (also for CheopsController) which means you have multiple versions of the class in the container. Maybe an older version is deployed on Tomcat?

EDIT

I didn't read the exception well enough, so I mislead you. peter.petrov is right, this is a Java version issue. Your project was compiled with Java 8, and your Tomcat servers are running on some previous Java version. You should compile your project with the same Java version as the server you plan to deploy it on is running on, or some previous version, since Java is backward compatible.

Predrag Maric
  • 23,938
  • 5
  • 52
  • 68
  • Yes, I'm using tomcat 7 on the client side, on the server they use tomcat 6. Is that such a huge difference? If I still get this error with tomcat 6 on the client side (If I change) how do I solve that? – benskiiii Feb 05 '15 at 16:01
  • Is `se.kth.webservices.rest.CategoryController` a class in your project, or from a dependency that you use? If it is your class, just make sure there are no other versions of the class other than in your `WEB-INF/classes` folder. If it is a dependency, then you must compile your project with the same dependency version as used on Tomcat. Since this is not a Tomcat class, the server version itself shouldn't have anything to do with it. – Predrag Maric Feb 05 '15 at 16:08
  • I changed my client version of tomcat to the right the same as server. But what do you mean with "compile your project with the same dependency version as used on Tomcat" ? Can you give some instructions (Sorry Im new to this) – benskiiii Feb 05 '15 at 16:12
  • @benskiiii Did you try a Google search? – peter.petrov Feb 05 '15 at 16:13
  • @benskiiii I didn't read the exception well enough, so I mislead you. peter.petrov is wright, this is a Java version issue. Your project was compiled with Java 8, and your Tomcat servers are running on some previous version. You should compile your project with the same Java version as the server you plan to deploy it on is running on. – Predrag Maric Feb 05 '15 at 16:20
  • I'm pretty sure that it has nothing to do with versions, since the project works when I run it in my IDE with tomcat 6.0... – benskiiii Feb 06 '15 at 08:31
  • @benskiiii It works because your IDE is compiling it and running it with the same Java version. But when you deploy to another server, your IDE compiles it with, for example, Java 7 and the server you are trying to deploy to is running on Java 6. That causes this exception. So, you have to **compile** the project with the same Java version that the target server uses (or older version, it will work because Java is backward compatible, but not newer version). – Predrag Maric Feb 06 '15 at 09:31
  • @benskiiii You are partially wright, it has nothing to do with Tomcat versions, but it has everything to do with Java versions. – Predrag Maric Feb 06 '15 at 09:33
  • Oh, okay. Now I understand. Is there anyway of solving this with a spring/maven project and rebuild the project with the right version? – benskiiii Feb 06 '15 at 09:36
  • Sure, if you use maven to build the project then check you can [configure maven compiler plugin](http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html). If you build the project with your IDE, then just configure the project in IDE to use Java version that you need. – Predrag Maric Feb 06 '15 at 09:43