Weblogic 12.2.1.x上的Jersey 1.13 Web服务

时间:2016-07-15 08:26:06

标签: jersey weblogic weblogic12c jersey-1.0

我正在尝试在Weblogic 12.2.1.x上运行一个非常简单的Jersey Web服务但我失败了

在我web.xml我有以下

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>jersey1test</display-name>
    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.jersey1test</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/srv/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Web服务资源本身非常简单

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("jersey1test")
public class Jersey1Resource
{

    @Path("hello")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response helloJersey()
    {
        return Response.status(Response.Status.OK).entity("Hello from Jersey 1").build();
    }

}

我的pom中只有1.13个球衣

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.13</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.13</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-multipart</artifactId>
    <version>1.13</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>

正如oracle page所示,我在使用我的战争部署的weblogic.xml中有以下内容

<wls:container-descriptor>
    <wls:prefer-application-packages>
        <!— jersey-bundle-*.jar->
        <wls:package-name>com.sun.jersey.*</wls:package-name>
        <wls:package-name>com.sun.research.ws.wadl.*</wls:package-name>
        <wls:package-name>com.sun.ws.rs.ext.*</package-name>

        <!— Jackson-*.jar ->
        <wls:package-name>org.codehaus.jackson.*</wls:package-name>

        <!— jettison-*.jar ->
        <wls:package-name>org.codehaus.jettison.*</wls:package-name>

        <!— jsr311*.jar ->
        <wls:package-name>javax.ws.rs.*</wls:package-name>

        <!— asm.jar ->
        <wls:package-name>org.objectweb.asm.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:container-descriptor>

战争部署得很好但是当我试图访问web服务时,我只收到一个未找到的响应(当它被部署到weblogic 12.1.3或Glassfish 3/4时,同样的URI btw工作)

我注意到的一件事是我在服务器日志中看到以下内容(我看不到任何异常)

<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192509> <Changing servlet class from com.sun.jersey.spi.container.servlet.ServletContainer (web.xml) to org.glassfish.jersey.servlet.ServletContainer.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.ResourceConfig because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.ApplicationAdapter because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.server.impl.application.DeferredResourceConfig because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.ClassNamesResourceConfig because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.DefaultResourceConfig because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.PackagesResourceConfig because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.servlet.WebAppResourceConfig because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.ClasspathResourceConfig because ApplicationPath annotation is not set on it.> 
<15-Jul-2016 08:39:55 o'clock BST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class com.sun.jersey.api.core.ScanningResourceConfig because ApplicationPath annotation is not set on it.>

对我而言似乎暗示它忽略了我在weblogic.xml中设置的内容。我究竟做错了什么?是否可以在weblogic 12.2.1.x中使用jersey 1 Web服务?

1 个答案:

答案 0 :(得分:1)

看起来12.2.1.x存在兼容性问题。

您可以选择降级您的WebLogic版本,或者升级到Jersey 2(为什么您还没有使用Jersey 2?)

https://community.oracle.com/thread/3923266?start=0&tstart=0