[英]Multiple prefixes in RestEasy configuration
I am using Jboss RestEasy web services, and I need to multiple url to map to that web service. 我正在使用Jboss RestEasy Web服务,并且需要多个URL才能映射到该Web服务。 Is there any possibility that I can set multiple prefixes for 'resteasy.servlet.mapping.prefixconfigured 我是否可以为'resteasy.servlet.mapping.prefixconfigured设置多个前缀
here is my configuration in web.xml 这是我在web.xml中的配置
<servlet-name>REST Service</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servletclass>
</servlet>
<servlet-mapping>
<servlet-name>REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>REST Service</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
I want service for both "/rest" and "/service" prefixes 我需要同时为“ / rest”和“ / service”前缀提供服务
For a quick test, I changed your <context-param>
into <init-param>
inside <servlet>
and in RESTeasy 3.0.5 it worked for me. 为了进行快速测试,我将<servlet>
内的<context-param>
更改为<init-param>
<servlet>
,在RESTeasy 3.0.5中它对我有用。
So a workaround might be to define two servlets with the same configuration and differing only on resteasy.servlet.mapping.prefix
value of <init-param>
's, and define two mappings for them. 因此,一种解决方法可能是定义两个具有相同配置且仅在<init-param>
的resteasy.servlet.mapping.prefix
值上不同的servlet,并resteasy.servlet.mapping.prefix
定义两个映射。
Beware that now you have two servlets that live their own lives (eg separate contexts and lifecycles), which might be unacceptable in some scenarios. 请注意,现在您有两个 servlet可以各自生存(例如,单独的上下文和生命周期),这在某些情况下可能是不可接受的。
UPDATE: Also take a look at this answer, similar to mine although more elaborated (I haven't tried it myself): https://stackoverflow.com/a/25487574/283519 更新:也看看这个答案,类似于我的,虽然更详细(我自己还没有尝试过): https : //stackoverflow.com/a/25487574/283519
@pwes Thanks a lot! @pwes非常感谢! I was looking to expose two RESTful services. 我当时打算公开两个RESTful服务。 Say /api1 and /api2 . 说/ api1和/ api2。 Your suggestion works for both what the OP wants and what I wanted too. 您的建议既适用于OP的需求,也适用于我的需求。
Here's how each servelet is configured: 这是每个servelet的配置方式:
<servlet>
<servlet-name>entity-manager</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>/api1</param-value>
</init-param>
</servlet>
Second one: 第二个:
<servlet>
<servlet-name>entity-manager</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>/api2</param-value>
</init-param>
</servlet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.