我从昨天开始尝试使用Jersey 1.18构建一个基本的RESTful Web服务,但是当直接从eclipse尝试时,它无法在Weblogic中部署它。后来我刚刚从eclipse导出了war文件,并使用Weblogic Console成功部署。为了直接从eclipse部署REST服务(Jersey 1.18),我还需要在eclipse中配置其他任何东西吗?以下是源和部署描述符: -
资源类: -
package com.ericsson.rest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("/TestResource")
public class TestResource {
/**
* Default constructor.
*/
public TestResource() {
// TODO Auto-generated constructor stub
}
/**
* Retrieves representation of an instance of TestResource
* @return an instance of String
*/
@GET
@Produces("text/html")
public String resourceMethodGET() {
// TODO Auto-generated method stub
return "<html>Hello Roy</html>";
}
/**
* PUT method for updating or creating an instance of TestResource
* @content content representation for the resource
* @return an HTTP response with content of the updated or created resource.
*/
@PUT
@Consumes("text/html")
public void resourceMethodPUT(String content) {
// TODO Auto-generated method stub
//throw new UnsupportedOperationException();
}
}
应用程序子类: -
package rest.application.config;
import java.util.Set;
import javax.ws.rs.core.Application;
import javax.ws.rs.ApplicationPath;
@ApplicationPath("test")
public class ApplicationConfig extends Application {
public Set<Class<?>> getClasses() {
return getRestClasses();
}
//Auto-generated from RESTful web service wizard
private Set<Class<?>> getRestClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
resources.add(com.ericsson.rest.TestResource.class);
return resources;
}
}
部署描述符: -
<?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>JAX_RS</display-name>
<servlet>
<servlet-name>RestServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>rest.application.config.ApplicationConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
获取资源的网址: -
http://localhost:7001/JAX_RS/test/TestResource
提前致谢!
答案 0 :(得分:0)
您可能需要考虑查看本文中的所有步骤:
http://me-ol-blog.blogspot.co.uk/2015/07/step-by-step-tutorial-on-how-to-create.html
它显示了在Eclipse中部署到weblogic。