Java REST轻松配置问题(Servlet容器4.0和JAX-RS 2.1)
我一直在尝试使用RESTEasy建立一个基本的rest服务,从10个多小时开始,我无法发现我做错了什么。请查看下面我的代码并让我知道。多谢各位 资源类Java REST轻松配置问题(Servlet容器4.0和JAX-RS 2.1),java,rest,maven,resteasy,Java,Rest,Maven,Resteasy,我一直在尝试使用RESTEasy建立一个基本的rest服务,从10个多小时开始,我无法发现我做错了什么。请查看下面我的代码并让我知道。多谢各位 资源类 import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; @Path("/test") @Produces("application/xml") public class Test
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/test")
@Produces("application/xml")
public class Test {
@GET
public Response testing() {
return Response.status(200).build();
}
}
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/rest")
public class TestApplication extends Application{
private Set<Object> singletons = new HashSet<>();
private Set<Class<?>> empty = new HashSet<>();
@Override
public Set<Class<?>> getClasses() {
return empty;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
资源应用类
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/test")
@Produces("application/xml")
public class Test {
@GET
public Response testing() {
return Response.status(200).build();
}
}
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/rest")
public class TestApplication extends Application{
private Set<Object> singletons = new HashSet<>();
private Set<Class<?>> empty = new HashSet<>();
@Override
public Set<Class<?>> getClasses() {
return empty;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
import java.util.HashSet;
导入java.util.Set;
导入javax.ws.rs.ApplicationPath;
导入javax.ws.rs.core.Application;
@应用程序路径(“/rest”)
公共类TestApplication扩展了应用程序{
private Set singleton=new HashSet();
private Set>getClasses(){
返回空;
}
@凌驾
公共集getSingleton(){
返回单身人士;
}
}
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>ims</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>InventoryMaintenanceSystem</name>
<url>http://maven.apache.org</url>
<description>This project deals with providing resources needed for Inventory Maintenance System</description>
<repositories>
<repository>
<id>jboss</id>
<name>jboss repo</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<finalName>ims</finalName>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.10.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.10.0.Final</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.1.jre8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</project>
4.0.0
com公司
.
请引导我找到解决方案,谢谢 我在这里尝试的URL感谢任何试图帮助我的人,我自己设法找到了解决方案。当我将maven依赖项添加到web部署程序集中时,问题得到了解决。