How to implement jaxrs Application without web.xml [duplicate]

做~自己de王妃 提交于 2019-12-05 18:09:19

You need to deploy your application into a Servlet 3.0 compliant container to take advantage of this functionality. Try GlassFish 3.x or Tomcat 7.

jabal

I have found a quite similar question and the problem found there could help you as well. I would definitely try it with an empty web.xml with 3.0 schema version to see if it helps.

JBoss AS 7 Restful Webservices not auto deploying

For those wishing to use the Servlet 2.0 specification, create a web.xml and add in the jersey servlet maven dependency:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="3.0"
    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">
    <servlet>
        <servlet-name>REST Service</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>com.mycompany.rest.engine.EngineApp</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

Add dependency to pom

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.13</version>
</dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!