Tomcat 集成 Resteasy

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/inforstack/article/details/78933080

修改项目pom.xml

<dependency>
	<groupId>org.jboss.resteasy</groupId>
	<artifactId>resteasy-jaxrs</artifactId>
	<version>3.1.4.Final</version>
</dependency>
<dependency>
	<groupId>org.jboss.resteasy</groupId>
	<artifactId>resteasy-jaxb-provider</artifactId>
	<version>3.1.4.Final</version>
</dependency>
<dependency>
	<groupId>org.jboss.resteasy</groupId>
	<artifactId>resteasy-servlet-initializer</artifactId>
	<version>3.1.4.Final</version>
</dependency>

定义Application

package com.inforstack.resteasy.api;
import javax.ws.rs.ApplicationPath;
@ApplicationPath(value = "/api")
public class Application extends javax.ws.rs.core.Application {

}

定义controller

package com.inforstack.resteasy.api;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/demo")
public class DemoService {
	@GET
	@Path("/list")
	public String getBooks() {
		return "demo";
	}
}


PS: 使用的Servlet需要版本3.0以上
启动tomcat之后打开浏览器输入:http://localhost:8080/resteasy/api/demo/list


猜你喜欢

转载自blog.csdn.net/inforstack/article/details/78933080