JAX-RS的错误

时间:2014-09-23 06:49:08

标签: jax-rs

首先,请告诉我,我的英语不好。因为我是日本人。 我问,JAX-RS项目的错误。 我导入以下网站的示例: http://www.opentone.co.jp/news/release/article04/article0403.html 但我无法执行该项目。

我认为"由于之前的错误而导致上下文失败:严重"是最重要的。 他们如何解决如果?

如果可能,上面的网站请尝试导入以实际删除项目。 你可以下载"添付のファイル"来自附件。在页面底部附近。

结束了,谢谢。

这是web.xml

   <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Archetype Created Web Application</display-name>

      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>

      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
      </context-param>

      <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>

      <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/*</url-pattern>
      </servlet-mapping>
        </web-app>

这是堆栈跟踪

9 23, 2014 5:18:07 午後 org.apache.catalina.core.StandardContext listenerStart
重大: クラス org.springframework.web.context.ContextLoaderListener のリスナインスタンスにコンテキスト初期化イベントを送信中の例外です
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [jp.sample.jaxrs.service.HelloResource] for bean with name 'helloResource' defined in file [C:\Users\omiz12032\workspace3\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\jax-rs\WEB-INF\classes\jp\sample\jaxrs\service\HelloResource.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: jp/sample/jaxrs/service/HelloResource : Unsupported major.minor version 52.0 (unable to load class jp.sample.jaxrs.service.HelloResource)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1264)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1330)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:896)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:566)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.UnsupportedClassVersionError: jp/sample/jaxrs/service/HelloResource : Unsupported major.minor version 52.0 (unable to load class jp.sample.jaxrs.service.HelloResource)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2858)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1282)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1253)
    ... 24 more

9 23, 2014 5:18:07 午後 org.apache.catalina.core.StandardContext start
重大: Error listenerStart
9 23, 2014 5:18:07 午後 org.apache.catalina.core.StandardContext start
重大: 以前のエラーのためにコンテキストの起動が失敗しました [/jax-rs]
9 23, 2014 5:18:07 午後 org.apache.catalina.core.ApplicationContext log
情報: Closing Spring root WebApplicationContext
9 23, 2014 5:18:07 午後 org.apache.coyote.http11.Http11Protocol start
情報: Coyote HTTP/1.1を http-8080 で起動します
9 23, 2014 5:18:07 午後 org.apache.jk.common.ChannelSocket init
情報: JK: ajp13 listening on /0.0.0.0:8009
9 23, 2014 5:18:07 午後 org.apache.jk.server.JkMain start
情報: Jk running ID=0 time=0/21  config=null
9 23, 2014 5:18:07 午後 org.apache.catalina.startup.Catalina start
情報: Server startup in 4681 ms

这是applicationContext.xml.Those,用于注册Web服务

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

  <import resource="classpath:META-INF/cxf/cxf.xml" />

  <context:component-scan base-package="jp.sample.jaxrs" />

  <jaxrs:server id="jaxrsservice" address="/">
      <jaxrs:serviceBeans>
          <ref bean="helloResource" />
      </jaxrs:serviceBeans>
  </jaxrs:server>

  <jaxrs:server id="itemorderresource" address="/">
      <jaxrs:serviceBeans>
          <ref bean="itemOrderResource" />
      </jaxrs:serviceBeans>
  </jaxrs:server>

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost/jaxrs" />
    <property name="username" value="jaxrs" />
    <property name="password" value="jaxrs" />
  </bean>

  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:mybatis-config.xml" />
    <property name="mapperLocations" value="classpath:mybatis/**/*.xml" />
  </bean>

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>
</beans>

1 个答案:

答案 0 :(得分:0)

  

引起:java.lang.UnsupportedClassVersionError:jp / sample / jaxrs / service / HelloResource:不支持的major.minor版本52.0(无法加载类jp.sample.jaxrs.service.HelloResource)

基本上,这意味着您使用比您的服务器更新的JDK编译您的类(可能在您拥有1.8的开发环境中以及在您拥有1.7的tomcat服务器中)。

尝试在开发环境中将Java编译器级别切换为较低版本。