我正在使用RestEasy开发Rest服务。我需要在Tomcat中进行部署。而且我认为我的web.xml中有问题
这是我的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>MyServices</display-name> <!-- Auto scan REST service --> <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> <!-- this need same with resteasy servlet url-pattern --> <context-param> <param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/services</param-value> </context-param> <servlet> <servlet-name>resteasy-servlet</servlet-name> <servlet-class> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher </servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>com.service.services.MessageApplication</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>resteasy-servlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> </web-app>
我有服务:
@GET @Path("/hello") @Produces({MediaType.APPLICATION_JSON}) public String Hello(String name) { System.out.println("Hello "+name); return("Hello "+name); }
当我进行部署时,我调用http://localhost:8080/MyServices/services/hello?name=Jesus Tomcat时显示此错误:
http://localhost:8080/MyServices/services/hello?name=Jesus
java.lang.ClassNotFoundException: org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:142) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 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:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
当包括在内时resteasy-cache-core-3.0.6.Final, resteasy-jackson-provider-3.0.6.Final, resteasy-jaxrs-3.0.6.Final, resteasy-oauth-3.0.6.Final, resteasy-servlet- initializer-3.0.6.Final and resteasy-validator- provider-11-3.0.6.Final,部署时间将出现下一个错误:
resteasy-cache-core-3.0.6.Final, resteasy-jackson-provider-3.0.6.Final, resteasy-jaxrs-3.0.6.Final, resteasy-oauth-3.0.6.Final, resteasy-servlet- initializer-3.0.6.Final and resteasy-validator- provider-11-3.0.6.Final
dic 24, 2013 4:04:02 PM org.apache.catalina.startup.Catalina start Grave: The required Server component failed to start so Tomcat is unable to start. org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.startup.Catalina.start(Catalina.java:691) 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:601) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 7 more Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 9 more Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 11 more
我不知道我的问题是什么。我需要将任何jar导入WEB-INF / lib吗?什么jar?我做错了什么?我不知道我是否以正确的方式致电我的服务。另外,我不知道为什么tomcat不运行。预先感谢。
您需要将resteasy库包含在WEB-INF / lib文件夹中。
您可以从此处下载它们http://sourceforge.net/projects/resteasy/files/Resteasy%20JAX- RS/
如果您使用Maven,则可以在以下位置找到依赖项:http://mvnrepository.com/artifact/org.jboss.resteasy/resteasy- jaxrs/