Java 泽西岛2号&x2B;春季4&x2B;jetty maven插件

Java 泽西岛2号&x2B;春季4&x2B;jetty maven插件,java,spring,maven,jersey,jetty,Java,Spring,Maven,Jersey,Jetty,我正在尝试使用jersey 2+spring 4+jetty maven插件制作一个示例。但是不断地出现这个错误,我不明白为什么。。请帮我一把 WARNING: The Jersey servlet application, named com.joejag.code.orders.restservices.ResourceConfiguration, is not annotated with ApplicationPath and has no servlet mapping. 2015-1

我正在尝试使用jersey 2+spring 4+jetty maven插件制作一个示例。但是不断地出现这个错误,我不明白为什么。。请帮我一把

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 o.e.j.m.p.JettyWebAppContext@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

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.joejag.code.orders</groupId>
    <artifactId>orders-server</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Example</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>4.2.3.RELEASE</spring.version>
        <jersey.version>2.22.1</jersey.version>
    </properties>

    <repositories>
        <repository>
            <id>maven2-repository.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>https://maven.java.net/content/groups/public/</url>
            <layout>default</layout>
        </repository>
    </repositories>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <!-- Jersey dependencies -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <!-- Spring dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Jersey + Spring -->
        <dependency>
            <groupId>org.glassfish.jersey.ext</groupId>
            <artifactId>jersey-spring4</artifactId>
            <version>3.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>

                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.6.v20151106</version>
                <configuration>
                    <scanTargets>
                        <scanTarget>${project.basedir}/src/main</scanTarget>
                        <scanTarget>${project.basedir}/src/test</scanTarget>
                    </scanTargets>
                    <webAppConfig>
                        <contextPath>/${project.artifactId}-${project.version}</contextPath>
                    </webAppConfig>
                    <contextPath>${project.artifactId}</contextPath>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
My applicationContext.xml

<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"
    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.xsd">

    <context:component-scan base-package="com.joejag.code.orders.restservices" />

    <bean id="transactionBo" class="TransactionBoImpl" />
    <!-- <bean class="OrderService" /> -->
</beans>

web.xml中的servlet名称必须一致。修复后,jetty能够加载servlet。

如果您去掉
javax.ws.rs.Application
init参数并在
资源配置
上添加
@ApplicationPath(“/”)
?@peeskillet相同的错误输出如果不使用jersey-spring4快照会发生什么,相反,使用jersey-spring3(2.22.1),只排除spring3工件,自己添加4s,如图所示。我看不出有什么错,这就是我为什么要问的原因。我从未使用过新的spring4快照,所以我只是想知道它是否有任何问题that@peeskillet对。我将回到您的建议,如果它仍然不在哪里。您的OrderServices类在类级别是否具有@Path。你能分享代码吗。
package com.joejag.code.orders.restservices;

import org.glassfish.jersey.server.ResourceConfig;

public class ResourceConfiguration extends ResourceConfig {
    public ResourceConfiguration() {
        register(OrdersService.class);
    }

}
<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"
    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.xsd">

    <context:component-scan base-package="com.joejag.code.orders.restservices" />

    <bean id="transactionBo" class="TransactionBoImpl" />
    <!-- <bean class="OrderService" /> -->
</beans>
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<String, String> orders = new TreeMap<String, String>();

   //@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 "<h2>Details on Order #" + order + "</h2><p>Customer name: " + orders.get(order);

      throw new WebApplicationException(Response.Status.NOT_FOUND);
   }

   @Path("/list")
   @GET
   @Produces("text/html")
   public String list()
   {
      String header = "<h2>All Orders</h2>\n";

      header += "<ul>";
      for (Map.Entry<String, String> order : orders.entrySet())
         header += "\n<li>#" + order.getKey() + " for " + order.getValue() + "</li>";

      header += "\n</ul>";

      return header;
   }
}