Weblogic:servlet在servlet-mapping中引用,但未在web.xml中定义

时间:2017-04-03 13:29:12

标签: rest jersey weblogic

获取此错误为何尝试在weblogic中部署战争

  

引起:weblogic.management.DeploymentException:[HTTP:101170]   Servlet Web Rest服务在servlet-mapping / myrest / *中引用   但没有在web.xml中定义。           在weblogic.servlet.internal.WebAppServletContext.verifyServletMappings(WebAppServletContext.java:1465)           在weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2809)           在weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)           在weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:822)           at weblogic.application.internal.ExtensibleModuleWrapper $ StartStateChange.next(ExtensibleModuleWrapper.java:360)

我的web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>REST</display-name>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>Jersey Web Application</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>rest.apis</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Web Rest Services</servlet-name>
        <url-pattern>/myrest/*</url-pattern>
    </servlet-mapping>
</web-app>

如果需要,我可以粘贴其余资源的代码,但不确定是否重要。

让我担心的是,weblogic会出现问题吗?

注意:最近的应用服务器已升级到weblogic 12.1.2

2 个答案:

答案 0 :(得分:3)

  

<servlet-name --> Jersey Web Application != Web Rest Services

<servlet-name>中的<servlet-mapping>应与<servlet-name>定义中的<servlet>相对应。因此错误

  

Servlet Web Rest服务在servlet-mapping / myrest / *中引用,但未在web.xml中定义

答案 1 :(得分:1)

为web.xml文件尝试此配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" 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_3_0.xsd">
<display-name>NAME</display-name>
<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
           <param-name>jersey.config.server.provider.packages</param-name>
           <param-value>YOUR REST CLASS PACKAGE</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>
</web-app>

在同一文件夹(web-app \ WEB-INF)中创建一个weblogic.xml文件,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<library-ref>  
    <library-name>jax-rs</library-name>  
    <specification-version>2.0</specification-version>
    <implementation-version>2.5.1</implementation-version>  
    <exact-match>false</exact-match>
</library-ref>
<container-descriptor>
    <prefer-application-packages>
        <package-name>org.glassfish.jersey.media.*</package-name>
        <package-name>org.glassfish.jersey.client.*</package-name>
        <package-name>org.glassfish.jersey.servlet.*</package-name> 
        <package-name>org.glassfish.jersey.jaxb.internal.*</package-name>   
        <package-name>com.sun.research.ws.wadl.*</package-name>
        <package-name>org.glassfish.hk2.*</package-name>
        <package-name>org.jvnet.hk2.*</package-name>
        <package-name>jersey.repackaged.org.objectweb.asm.*</package-name>
        <package-name>org.objectweb.asm.*</package-name>
        <package-name>com.sun.ws.rs.ext.*</package-name>
        <package-name>org.aopalliance.*</package-name>
        <package-name>javax.annotation.*</package-name>
        <package-name>javax.inject.*</package-name>
        <package-name>javax.ws.rs.*</package-name>
        <package-name>jersey.repackaged.com.google.common.*</package-name>
        <package-name>javassist.*</package-name>
    </prefer-application-packages>
</container-descriptor>
<context-root>YOUR_ROOT</context-root>
</weblogic-web-app>