![](/img/trans.png)
[英]Create RESTful Web Service with JAX-RS and deploy it to tomcat
[英]How to deploy a jax-rs web service to apache tomcat?
將桌面應用程序的示例Web服務部署到tomcat時遇到麻煩。
這是我的課
AppConfig.java
@ApplicationPath("sample-ws")
public class AppConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new HashSet<Class<?>>();
resources.add(HelloWorld.class);
return resources;
}
}
HelloWorld.java
@Path("hello-world")
public class HelloWorld {
@GET
public String hello(){
return "hello world";
}
}
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.sample</groupId>
<artifactId>sample-ws</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<finalName>sample-ws</finalName>
</build>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
我不知道在web.xml中寫什么,也無法正常工作。 我想念什么?
PS如果這很重要,我正在使用apache-tomcat-8.0.23
在web.xml中,您應該添加一個用於啟動框架的偵聽器,以及Web服務的url映射。 看看這篇文章: http : //www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/
但是,您的web.xml看起來應與此類似:
<web-app>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.