我正在尝试提供简单的Rest服务,并将该应用程序部署在wildfly服务器上,当我尝试在服务器上部署我的应用程序时,我遇到以下异常:
Cannot upload deployment: {"WFLYCTL0080: Failed services" =>
{"jboss.undertow.deployment.default-server.default-host./resttestapp" =>
"org.jboss.msc.service.StartException in service
jboss.undertow.deployment.default-server.default-host./resttestapp:
com.sun.jersey.api.container.ContainerException: The ResourceConfig
instance does not contain any root resource classes. Caused by:
com.sun.jersey.api.container.ContainerException: The ResourceConfig
instance does not contain any root resource classes."}}
我已经从stackoverflow中尝试了很多东西,但是对我来说没有用。
我使用的是Wildfly 9.0.2(独立版,通过管理控制台进行部署),这是Intellij的想法。
这是我pom.xml的一部分:
<groupId>cz.prg.rob</groupId>
<artifactId>resttestapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>resttestapp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<jersey.version>1.19.4</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
</dependencies>
这是我的web.xml:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>cz.prg.rob</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
这是我的服务类别:
package cz.prg.rob;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import java.util.Date;
@Path("/name")
public class UserService {
@GET
@Produces("text/plain")
public String getName() {
return "Qwerty";
}
@GET
@Path("/user")
@Produces("application/json")
public User getUser(@QueryParam("name") String name, @QueryParam("surname") String surname, @QueryParam("birthDate") Date birthDate) {
return new User(name, surname, birthDate);
}
}
这是我的User(模型)类的一部分:
@NoArgsConstructor
@AllArgsConstructor
@Data
public class User {
private String name;
private String surname;
private Date birthDate;
}
这是我的项目结构:
我不明白我在做什么错。请帮助我。
答案 0 :(得分:0)
对我有帮助的解决方案:
我已将其添加为JerseyServlet的init参数
print
这是我定义资源类的类
Foo
所以看起来我不得不对jersey说哪些类是资源类。如果要添加新的资源类,只需将它们在HashSet中添加到getClasses()方法中即可。