edw*_*yte 5 java rest jax-rs jersey
我试图在没有 web.xml 配置的情况下部署一个非常简单的 jaxrs 应用程序,但无法使其工作。我希望访问的 URL 是 serverandport/{appname}/rest/welcomes/hello,我想我一定遗漏了一些显而易见的东西。
应用
@ApplicationPath("/rest")
public class EngineApp extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(RestTestImpl.class);
return s;
}
}
Run Code Online (Sandbox Code Playgroud)
资源
@Path("/welcomes")
public class RestTestImpl {
@GET
@Path("hello")
public String sayPlainHello() {
return "Hi from Rest";
}
}
Run Code Online (Sandbox Code Playgroud)
POM 片段
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
Run Code Online (Sandbox Code Playgroud)
编辑:对于下面的响应,我尝试使用空的 web.xml 以及以下 web.xml。麻烦也返回 404,但是下面的 xml 声明“Servlet javax.ws.rs.core.Application 不可用”:
网页.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0"
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_2_5.xsd" >
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16657 次 |
| 最近记录: |