jersey 2 + spring 4 + jetty-maven-plugin

我试图用一个使用jersey 2 + spring 4 + jetty-maven-plugin的例子。 但不断得到这个错误,无法理解为什么..请给我一个手。

WARNING: The Jersey servlet application, named com.joejag.code.orders.restservices.ResourceConfiguration, is not annotated with ApplicationPath and has no servlet mapping. 2015-12-16 19:56:38.746:INFO:/.0-SNAPSHOT:main: Spring WebApplicationInitializers detected on classpath: [org.glassfish.jersey.server.spring.SpringWebApplicationInitializer@2776015d] 2015-12-16 19:56:38.778:WARN:oejw.WebAppContext:main: Failed startup of context oejmpJettyWebAppContext@15fb7a32{/orders-server-1.0-SNAPSHOT,file:///home/bryan-1/workspace/project/java/simple-java-restful-service-using-jersey-and-maven-master/src/main/webapp/,STARTING}{file:///home/bryan-1/workspace/project/java/simple-java-restful-service-using-jersey-and-maven-master/src/main/webapp/} java.lang.IllegalStateException: No such servlet: Example 

我的POM.xml

  4.0.0 com.joejag.code.orders orders-server war 1.0-SNAPSHOT Example  UTF-8 4.2.3.RELEASE 2.22.1    maven2-repository.java.net Java.net Repository for Maven https://maven.java.net/content/groups/public/ default     junit junit 4.8.2 test    org.glassfish.jersey.containers jersey-container-servlet ${jersey.version}   org.glassfish.jersey.core jersey-server ${jersey.version}    org.springframework spring-web ${spring.version} compile   org.springframework spring-core ${spring.version}   org.springframework spring-context ${spring.version}    org.glassfish.jersey.ext jersey-spring4 3.0-SNAPSHOT      maven-compiler-plugin 3.3  1.8 1.8    org.eclipse.jetty jetty-maven-plugin 9.3.6.v20151106   ${project.basedir}/src/main ${project.basedir}/src/test   /${project.artifactId}-${project.version}  ${project.artifactId}      

我的web.xml

  Example  org.springframework.web.context.ContextLoaderListener   contextConfigLocation classpath:applicationContext.xml   Jersey Web Application org.glassfish.jersey.servlet.ServletContainer  javax.ws.rs.Application com.joejag.code.orders.restservices.ResourceConfiguration  <!--  com.sun.jersey.config.property.packages com.joejag.code.orders.restservices  --> 1   Example /*   

我的ResourceConfig类

 package com.joejag.code.orders.restservices; import org.glassfish.jersey.server.ResourceConfig; public class ResourceConfiguration extends ResourceConfig { public ResourceConfiguration() { register(OrdersService.class); } } 

我的applicationContext.xml

    <!--  -->  

EDITED

在修复了不一致的servlet-name问题后,Jetty能够加载servlet,但是出现了一个新问题,即所有的@PUT方法似乎都不再执行了。 这里的OrderService看起来像。

 package com.joejag.code.orders.restservices; import java.util.Map; import java.util.TreeMap; import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** // * curl -X PUT http://127.0.0.1:8080/orders-server/orders/1?customer_name=bob // * curl -X GET http://127.0.0.1:8080/orders-server/orders/1 * curl -X GET http://127.0.0.1:8080/orders-server/orders/list */ @Component @Path("orders") public class OrdersService { public static Map orders = new TreeMap(); //@Autowired //private TransactionBo transactionBo; public OrdersService() { //his.transactionBo = transactionBo; } @Path("/{order}") @PUT @Produces("text/html") public String create(@PathParam("order") String order, @QueryParam("customer_name") String customerName) { orders.put(order, customerName); return "Added order #" + order ;//+ this.transaction.save(); } @Path("/{order}") @GET @Produces("text/html") public String find(@PathParam("order") String order) { if (orders.containsKey(order)) return "

Details on Order #" + order + "

Customer name: " + orders.get(order); throw new WebApplicationException(Response.Status.NOT_FOUND); } @Path("/list") @GET @Produces("text/html") public String list() { String header = "

All Orders

\n"; header += "
    "; for (Map.Entry order : orders.entrySet()) header += "\n
  • #" + order.getKey() + " for " + order.getValue() + "
  • "; header += "\n
"; return header; } }

web.xml中的servlet-name必须是一致的。 修复后,该docker能够加载servlet。