多个 JAX-RS 应用程序

发布于 2024-12-26 22:07:52 字数 548 浏览 0 评论 0原文

我已在 web.xml 中指定了我的 JAX-RS 应用程序,如下所示:

<servlet>
<servlet-name>CXFServlet</servlet-name>     
<servlet-class>
org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>
com.myapp.MYRestApplication       
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> 

我是否可以将另一个 JAX-RS 应用程序类传递给此 CXF servlet?

问候, 阿南德

I have specified my JAX-RS Application in the web.xml as follows:

<servlet>
<servlet-name>CXFServlet</servlet-name>     
<servlet-class>
org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>
com.myapp.MYRestApplication       
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> 

Is it possible for me to pass another JAX-RS application class to this CXF servlet?

Regards,
Anand

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱ヾ落雨殇 2025-01-02 22:07:52

虽然 CXF 可以在单个 servlet 中管理多个 JAX-RS 应用程序(我在自己的代码中使用此配置),但它足够复杂,因此您最好切换到使用基于 Spring 的配置。 CXFNonSpringJaxrsServlet 只能支持有限的配置。在我的代码中,我有这个(有点复杂,因为我也使用 Spring 安全性,但你可以删除该过滤器):

<!-- Location of the main Spring/CXF configuration file -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/beans.xml</param-value>
</context-param>

<!-- Apply Spring Security as a wrapper to everything --> 
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Hook for Spring lifecycle management; you want this -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- A single servlet to handle all CXF processing -->
<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

While CXF can manage multiple JAX-RS applications within a single servlet — I use this configuration in my own code — it is sufficiently complex that you're far better off switching to using a Spring-based configuration. The CXFNonSpringJaxrsServlet can only support limited configuration. In my code, I have this (a little complex because I'm also using Spring security, but you can drop that filter):

<!-- Location of the main Spring/CXF configuration file -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/beans.xml</param-value>
</context-param>

<!-- Apply Spring Security as a wrapper to everything --> 
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Hook for Spring lifecycle management; you want this -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- A single servlet to handle all CXF processing -->
<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文