首先,我是这个环境的新手.我以前开发过
Java,但不是应用程序服务器.从来没有这样做过,我以前从未使用过JBoss或WildFly.
我已经能够设置并运行WildFly服务器,并在127.0.0.1:9990访问它.当我部署.war文件时,服务器没有反应,我无法访问URL.
WildFly服务器确实声明我的部署成功并且处于活动状态,然后我尝试访问:127.0.0.1:8080 / RECAPP-API / rest / message / test,我得到404(找不到页面错误).
我正在使用Maven,所以首先,我的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.test.recapp.rest</groupId>
- <artifactId>RECAPP-API</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <version>3.0.6.Final</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jackson-provider</artifactId>
- <version>3.0.6.Final</version>
- </dependency>
- </dependencies>
- </project>
我的JSONService.java:
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.Produces;
- import javax.ws.rs.core.Response;
- @Path("/message")
- public class JSONService {
- @GET
- @Path("/{param}")
- @Produces("application/json")
- public Response printMessage(@PathParam("param") String msg) {
- String result = "Restful example: " + msg;
- return Response.status(200).entity(result).build();
- }
- }
最后,我的web.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- id="WebApp_ID" version="3.0">
- <display-name>RECAPP-API</display-name>
- <context-param>
- <param-name>resteasy.scan</param-name>
- <param-value>true</param-value>
- </context-param>
- <context-param>
- <param-name>resteasy.servlet.mapping.prefix</param-name>
- <param-value>/rest</param-value>
- </context-param>
- <listener>
- <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
- </listener>
- <servlet>
- <servlet-name>resteasy-servlet</servlet-name>
- <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>resteasy-servlet</servlet-name>
- <url-pattern>/rest/*</url-pattern>
- </servlet-mapping>
- </web-app>
谢谢你的帮助.
解决方法
快速启动的最佳方法是使用此依赖项.
- <dependency>
- <groupId>javax</groupId>
- <artifactId>javaee-api</artifactId>
- <version>7.0</version>
- <scope>provided</scope>
- </dependency>
并添加一个扩展应用程序类的类
- @ApplicationPath("rest")
- public class ConfigApp extends Application {
- public ConfigApp(){
- }
- }
而已.没有web.xml更改(仅限不需要web.xml).
并使用host:port /< warname> / rest /< endpoint path>访问您的休息端点