ich ein Jersey 2.x-Service erschaffe zu schlagen versuchen, mit Servlet 3.1 ohne web.xml Mein pom unten gegeben:Ich erhalte einen 404 Not Found Fehler, wenn ein Jersey 2 Service
<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</groupId>
<artifactId>testex</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>testex 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>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</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>testex</finalName>
</build>
</project>
ich habe den Dienst mit @ApplicationPath Ressource Config unten konfiguriert:
package com.testex.service;
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
@ApplicationPath("resources")
public class TestexResourceConfig extends ResourceConfig {
public TestexResourceConfig() {
super();
registerClasses(TestexService.class);
}
}
Und mein Service ist unten angegeben:
package com.testex.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.testex.config.Config;
import com.testex.config.ConfigLoader;
import com.testex.provider.ProjectDetailsProvider;
import com.testex.provider.VersionsProvider;
import com.testex.provider.bean.Project;
import com.google.gson.Gson;
@Path("/rest")
public class TestexService {
private final Config config;
public TestexService() {
super();
config = ConfigLoader.getConfig();
}
@GET
@Path("getDefaultProjectId")
@Produces(MediaType.APPLICATION_JSON)
public Response getDefaultProjectId() {
return Response.status(200).entity(new Gson().toJson(new Project(String.valueOf(config.getProjectId()))))
.build();
}
@GET
@Path("getProjectDetails")
@Produces(MediaType.APPLICATION_JSON)
public Response getProjectDetails(@QueryParam("projectId") int projectId) {
return Response.status(200).entity(new Gson().toJson(new ProjectDetailsProvider().getProjectDetails(projectId)))
.build();
}
@GET
@Path("getProjectVersionDetails")
@Produces(MediaType.APPLICATION_JSON)
public Response getProjectVersionDetails(@QueryParam("projectId") int projectId) {
return Response.status(200).entity(new Gson().toJson(new VersionsProvider().getVersionsForProject(projectId)))
.build();
}
}
Darauf zu Tomcat 8 auf Kontext root "testex" bereitstellen, schlug ich die folgende URL:
http://localhost:8080/testex/resources/rest/getDefaultProjectId
Aber ich bekomme einen 404 Not Found error. Bitte helfen Sie.