【发布时间】:2016-12-27 23:00:04
【问题描述】:
我整整一周都在努力让它工作,但即使使用一个简单的 rest hello world 应用程序,我也无法让 wildfly 工作...... 浏览了所有 Resteasy 文档、wildfly resteasy 示例、几个教程、链接到 wildfly 和 resteasy 的 maven 文档,但仍然...
我使用 JDK 1.8、wildfly 10.x 和 resteasy 3.0.19(这是我的 wildfly 默认版本)。
wildfly 似乎只是不想看到战争的内容。我的意思是 web.xml 没问题,但我的课程是完全透明的。尝试在本地定义 resteasy servlet 时,我的应用程序类上没有找到 classnotfound,而在使用 wildfly 内置 servlet 时什么也没有。
这是我的最后一个 pom.xml、web.xml 和一个也是唯一的 java 类(我已经尝试使用 javax.ws.rs.Application 类和注释,结果相同。我还尝试使用自定义 servlet 映射和所有...... .).
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.me.test</groupId>
<artifactId>testrest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>testrest Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
<version>jdk</version>
<scope>system</scope>
<systemPath>C:/Program Files/Java/jdk1.8.0_112/lib/jconsole.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>testrest</finalName>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<!-- this tells RESTEasy to load resource classes -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
和我唯一的班级:
package com.me.services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("/hello")
public class HelloService {
@GET
@Produces("text/plain")
public String sayHello() {
return "Hello World";
}
}
当我在部署后尝试访问我的服务时,我得到了: http://localhost:8080/testrest/:世界你好! (来自我的 index.html 文件) http://localhost:8080/testrest/rest:未找到 localhost:8080/testrest/rest/hello : 未找到
当我在 wildfly 中检查我的部署时,我可以看到我的应用程序,但在 undertow 中没有 servlet...
正如之前解释的那样,我尝试了很多事情,比如尝试在 web.xml 中声明我自己的 servlet 时它可以工作,但是它无法在战争中找到应用程序类,尽管它实际上就在那里......真的好像 Wildfly 没有'从我的 web.xml 看不到任何东西:/
【问题讨论】:
-
如果将 /rest/* 更改为 /* 会发生什么?