Jersey REST 404错误

时间:2016-04-11 20:44:05

标签: java rest tomcat jersey jersey-2.0

免责声明: 我搜索了整个StackOverflow网络,看到了很多不同解决方案的问题,但没有任何帮助,因为他们中的大多数都有拼写错误,或者错误.war文件名等。请不要将问题标记为重复。

对于我正在处理的最新项目,我需要使用 Jersey REST 服务,但我完全陷入404错误

这是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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>VideoConverter</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>VideoConverter REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>videoconverter.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>VideoConverter REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

然后,这是我需要调用的REST方法的实现:

@Path("/convert")
public class ConvertControllerREST {
    @GET
    @Path("/getcommands")
    @Produces("application/json")
    public List<JSONObject> getCommands() {
        // other logic here
    }

我在以下网址上调用此REST方法:http://10.0.2.15:8080/VideoConverter/rest/convert/getcommands

Tomcat 7日志完全没有显示错误,只有404 - 在请求URL时找不到。从这里下载了最新的Jersey版本:https://jersey.java.net/download.html(RI包),并将我在上面的bundle中找到的所有.jar文件插入到WEB-INF / lib文件夹中。另外,我创建的.war文件与web.xml文件中声明的名称相同:VideoConverter.war。

任何想法可能会出现问题吗?

更新1:

我在项目中使用的所有jar

enter image description here

以下是日志:

catalina.out

Apr 12, 2016 2:49:21 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common/classes], exists: [false], isDirectory: [false], canRead: [false]
Apr 12, 2016 2:49:21 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common], exists: [false], isDirectory: [false], canRead: [false]
Apr 12, 2016 2:49:21 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server/classes], exists: [false], isDirectory: [false], canRead: [false]
Apr 12, 2016 2:49:21 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server], exists: [false], isDirectory: [false], canRead: [false]
Apr 12, 2016 2:49:21 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared/classes], exists: [false], isDirectory: [false], canRead: [false]
Apr 12, 2016 2:49:21 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared], exists: [false], isDirectory: [false], canRead: [false]
Apr 12, 2016 2:49:23 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Apr 12, 2016 2:49:23 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1917 ms
Apr 12, 2016 2:49:23 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 12, 2016 2:49:23 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52 (Ubuntu)
Apr 12, 2016 2:49:23 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/manager.xml
Apr 12, 2016 2:49:25 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/examples.xml
Apr 12, 2016 2:49:29 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Apr 12, 2016 2:49:29 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Apr 12, 2016 2:49:29 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/docs.xml
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/host-manager.xml
Apr 12, 2016 2:49:30 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/VideoConverter.war
Apr 12, 2016 2:49:31 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/VideoConverter/WEB-INF/lib/javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Apr 12, 2016 2:49:36 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT
Apr 12, 2016 2:49:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Apr 12, 2016 2:49:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11743 ms
Apr 12, 2016 3:03:56 PM org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/VideoConverter]] after stop() had already been called. The second call will be ignored.
Apr 12, 2016 3:03:56 PM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/VideoConverter]
Apr 12, 2016 3:10:10 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/VideoConverter.war
Apr 12, 2016 3:10:11 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/VideoConverter/WEB-INF/lib/javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class

localhost_access_log.2016-04-12.txt

10.0.2.15 - - [12/Apr/2016:15:03:43 +0200] "GET /favicon.ico HTTP/1.1" 404 991
10.0.2.15 - - [12/Apr/2016:15:03:45 +0200] "GET /manager/html HTTP/1.1" 401 2486
10.0.2.15 - admin [12/Apr/2016:15:03:52 +0200] "GET /manager/html HTTP/1.1" 200 17602
10.0.2.15 - admin [12/Apr/2016:15:03:55 +0200] "POST /manager/html/stop?path=/VideoConverter&org.apache.catalina.filters.CSRF_NONCE=1DA71E984234CCADB786702A69EA8151 HTTP/1.1" 200 17100
10.0.2.15 - admin [12/Apr/2016:15:03:56 +0200] "POST /manager/html/undeploy?path=/VideoConverter&org.apache.catalina.filters.CSRF_NONCE=8B039406F2DB0A12F2712FA64870DEC0 HTTP/1.1" 200 15899
10.0.2.15 - admin [12/Apr/2016:15:03:57 +0200] "GET /manager/html/list?org.apache.catalina.filters.CSRF_NONCE=60166501ABF61EE3570F9E1E2E01FE39 HTTP/1.1" 200 15841
10.0.2.15 - admin [12/Apr/2016:15:09:58 +0200] "GET /manager/html/list?org.apache.catalina.filters.CSRF_NONCE=5296AEE64D04DF76D1A89216AF48B5F0 HTTP/1.1" 200 15841
10.0.2.15 - admin [12/Apr/2016:15:10:21 +0200] "POST /manager/html/upload?org.apache.catalina.filters.CSRF_NONCE=8A82CD1444765A92D6DD5722490C520E HTTP/1.1" 200 17602
10.0.2.15 - admin [12/Apr/2016:15:10:23 +0200] "GET /manager/html/list?org.apache.catalina.filters.CSRF_NONCE=AEF53F6C5831950965CC133FB5E51C5E HTTP/1.1" 200 17602
10.0.2.15 - - [12/Apr/2016:15:11:30 +0200] "GET /VideoConverter/ HTTP/1.1" 200 416
10.0.2.15 - - [12/Apr/2016:15:11:33 +0200] "GET /VideoConverter/SignUpServlet HTTP/1.1" 200 3456
10.0.2.15 - - [12/Apr/2016:15:11:36 +0200] "GET /VideoConverter/Convert HTTP/1.1" 200 963
10.0.2.15 - - [12/Apr/2016:15:11:36 +0200] "GET /VideoConverter/js/jquery-2.2.3.min.js HTTP/1.1" 304 -
10.0.2.15 - - [12/Apr/2016:15:11:36 +0200] "GET /VideoConverter/js/angular.min.js HTTP/1.1" 304 -
10.0.2.15 - - [12/Apr/2016:15:11:36 +0200] "GET /VideoConverter/js/ConvertController/convert.js HTTP/1.1" 304 -
10.0.2.15 - - [12/Apr/2016:15:11:36 +0200] "GET /VideoConverter/js/main.js HTTP/1.1" 304 -
10.0.2.15 - - [12/Apr/2016:15:11:36 +0200] "GET /VideoConverter/rest/convert/getcommands HTTP/1.1" 404 967

更新2:

似乎我错过了一些引发错误的重要日志:

localhost.2016-04-12.log

Apr 12, 2016 3:03:51 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: init: Associated with Deployer 'Catalina:type=Deployer,host=localhost'
Apr 12, 2016 3:03:51 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: init: Global resources are available
Apr 12, 2016 3:03:51 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
Apr 12, 2016 3:03:54 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: stop: Stopping web application '/VideoConverter'
Apr 12, 2016 3:03:55 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
Apr 12, 2016 3:03:56 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: undeploy: Undeploying web application at '/VideoConverter'
Apr 12, 2016 3:03:56 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
Apr 12, 2016 3:03:57 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
Apr 12, 2016 3:09:58 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
Apr 12, 2016 3:10:21 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet VideoConverter REST Service as unavailable
Apr 12, 2016 3:10:21 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /VideoConverter threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1143)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1648)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1445)
    at org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:284)
    at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:206)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    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)

Apr 12, 2016 3:10:21 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
Apr 12, 2016 3:10:23 PM org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'

更新3:

更改<servlet-class>后:

<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

为:

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

日志:

Apr 12, 2016 3:26:49 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/VideoConverter.war
Apr 12, 2016 3:26:50 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/VideoConverter/WEB-INF/lib/javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Apr 12, 2016 3:26:57 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT
Apr 12, 2016 3:26:59 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Apr 12, 2016 3:26:59 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 12173 ms
Apr 12, 2016 3:27:06 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<org.json.JSONObject>.
Apr 12, 2016 3:27:12 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<org.json.JSONObject>.

更新4(在media type=application/json中找到问题后):

收到新错误:

javax.servlet.ServletException: Servlet.init() for servlet VideoConverter REST Service threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:745)

java.lang.NoClassDefFoundError: com/fasterxml/jackson/jaxrs/json/JacksonJaxbJsonProvider
    org.glassfish.jersey.jackson.JacksonFeature.configure(JacksonFeature.java:85)
    org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:730)
    org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:648)
    org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:829)
    org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:453)
    org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
    org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
    org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
    org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
    org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
    org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
    org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:745)

最终更新 @Meiko的答案解决了一半的问题。因为出现了新的错误,我决定采取他的建议并将项目转换为Maven archtype以轻松解决这些问题。

1 个答案:

答案 0 :(得分:1)

在您的web.xml中编辑package scanninginit-param

<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>videoconverter.rest</param-value>
</init-param>

或(XOR!)将球衣更新为2.x并更改servlet-class

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

com.sun.jerseyjersey 1.x的包名称。

org.glassfish.jerseyjersey 2.x的基础包。

<强>更新

问题:

  

SEVERE:找不到媒体类型= application / json的MessageBodyWriter,type = class java.util.ArrayList,genericType = java.util.List

您必须添加一个能够序列化/反序列化JSON的库(处理指定的媒体类型)。请参阅:https://jersey.java.net/documentation/latest/media.html#json

此处还介绍了如何执行此操作: SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.jersey.jaxb.Todo, genericType=class com.jersey.jaxb.Todo

只需在此处下载资料包:http://central.maven.org/maven2/org/glassfish/jersey/media/jersey-media-json-jackson/2.22.2/jersey-media-json-jackson-2.22.2.jar

和:http://central.maven.org/maven2/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.7.3/jackson-jaxrs-json-provider-2.7.3.jar

将罐放入类路径中......

将标记servlet-class编辑为<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>,如图所示。 这应该足够了。

建议:我真的建议你使用maven。使用maven原型,您可以非常轻松地设置项目:

mvn archetype:generate \
    -DarchetypeArtifactId=jersey-quickstart-webapp \
    -DarchetypeGroupId=org.glassfish.jersey.archetypes \
    -DinteractiveMode=false \
    -DgroupId=com.example \
    -DartifactId=simple-service-webapp \
    -Dpackage=com.example \
    -DarchetypeVersion=2.22.2

启动此应用程序:

mvn clean package tomcat7:run-war