0
自從昨天以來,我一直在試圖用Jersey 1.18構建一個基本的REST風格的webservice,但是在直接從eclipse直接嘗試時卻無法將其部署到Weblogic中。後來我剛剛從eclipse中導出了一個war文件,並使用Weblogic Console成功部署。我還需要在eclipse中配置其他任何東西,以便直接從eclipse部署REST服務(Jersey 1.18)。下面是源和部署描述符: -REST Webservice with Weblogic12c + Jersey 1.18 + Eclipse Juno
資源類: -
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進行部署時,在手動部署過程中沒有問題時會出現什麼錯誤? –
使用netbeans :) –