RestEasy服务的多个前缀

时间:2018-12-06 14:20:08

标签: java rest jax-rs resteasy

我的RestEasy项目中需要有多个前缀。同样,我在web.xml中定义了多个servlet。

<servlet>
    <servlet-name>resteasy-servlet1</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <init-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest1</param-value>
    </init-param>       
    <init-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.test.rs.TokenGenerator</param-value>
    </init-param>
</servlet>

<servlet>
    <servlet-name>resteasy-servlet2</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <init-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest2</param-value>
    </init-param>       
    <init-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.test.rs.ResourceProvider</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>resteasy-servlet1</servlet-name>
    <url-pattern>/rest1/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>resteasy-servlet2</servlet-name>
    <url-pattern>/rest2/*</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>AuthFilter</filter-name>
    <filter-class>com.test.rs.filter.AuthFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>AuthFilter</filter-name>
    <url-pattern>/rest2/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>

stackoverflow post中定义了相同的方法,但是 我尚未在我的项目中使用它。尝试访问下面的网址时,我总是会遇到404 Not Found错误。谁能突出显示我在配置中缺少的内容?

  

http://localhost:8080/rstest/rest1/token

     

http://localhost:8080/rstest/rest2/resource

部署的项目的Web上下文根为rstest

我的班级的@Path注释定义如下

@Path("/token")
public class TokenGenerator {

0 个答案:

没有答案