Jersey服务在Web模块3.1上给出404 Not found错误

时间:2016-03-14 08:35:25

标签: java jersey

我有泽西网络服务,如下所示

@Path("/rest")
public class AntimissService {
    @Context
    ServletContext context;

    @GET
    @Path("get")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getResponse() {
        return Response.status(200).entity("some_json_here").build();
    }
}

当我在使用Web Module 3.1时,我没有配置web.xml。我只使用注释进行配置。为了对这项服务采取行动,我增加了以下课程

@ApplicationPath("/antimiss")
public class ServiceContext extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<>();
        classes.add(AntimissService.class);
        return classes;
    }
}

但是当我尝试在此路径上运行Web服务时:http://localhost:8080/antimiss/rest/get,我得到404 Not Found - 请求的资源不可用。 我想让应用程序完全免于web.xml。任何帮助表示赞赏。

编辑:我有所有必需的罐子,下面是我的pom: EDIT2:更新了pom

    <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.adobe</groupId>
    <artifactId>antimiss</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>antimiss Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.19.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.19.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.19.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
        <finalName>antimiss</finalName>
    </build>
</project>

EDIT3:以下是服务器启动日志

Mar 14, 2016 3:11:57 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:antimiss' did not find a matching property.
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.30
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Dec 1 2015 22:30:46 UTC
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.30.0
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            4.4.3-300.fc23.x86_64
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /usr/java/jdk1.8.0_66/jre
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_66-b17
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /home/rlocal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /home/rlocal/apache-tomcat-8.0.30
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/rlocal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/home/rlocal/apache-tomcat-8.0.30
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/rlocal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/home/rlocal/apache-tomcat-8.0.30/endorsed
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Mar 14, 2016 3:11:57 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Mar 14, 2016 3:11:57 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 14, 2016 3:11:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 14, 2016 3:11:57 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Mar 14, 2016 3:11:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 14, 2016 3:11:57 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 419 ms
Mar 14, 2016 3:11:57 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 14, 2016 3:11:57 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.30
Mar 14, 2016 3:11:58 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 14, 2016 3:12:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Mar 14, 2016 3:12:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Mar 14, 2016 3:12:46 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 48882 ms

项目名称是antimiss。

0 个答案:

没有答案