【发布时间】:2014-12-22 12:00:35
【问题描述】:
从昨天开始,我一直在尝试使用 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>
获取资源的 URL:-
http://localhost:7001/JAX_RS/test/TestResource
提前致谢!
【问题讨论】:
-
从 Eclipse 部署时遇到哪些在手动部署期间没有问题的错误?
标签: eclipse web-services rest jersey weblogic12c