gpt4 book ai didi

spring - Resteasy 和 Spring 集成,无需 Spring ContextLoadListener

转载 作者:行者123 更新时间:2023-12-02 07:25:53 25 4
gpt4 key购买 nike

我在我的项目中使用 Resteasy 和 Spring。正如 Resteasy 文档中所述:http://docs.jboss.org/resteasy/docs/3.0.1.Final/userguide/html_single/index.html#RESTEasy_Spring_Integration .

我需要在 web.xml 文件中添加一个监听器:

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

<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>

但是,在我的项目中我们还使用了一个名为 Magnolia 的 cms,并且 Magnolia 也有 SpringContextLoaderListener 的实现。如果我放置两个上下文监听器。当我运行应用程序时,magnolia 将不会启动。

所以根据 Resteasy 文档说:

If you do not use a Spring ContextLoaderListener to create your bean factories, then you can manually register the RESTeasy BeanFactoryPostProcessor by allocating an instance of org.jboss.resteasy.plugins.spring.SpringBeanProcessor. You can obtain instances of a ResteasyProviderFactory and Registry from the ServletContext attributes org.jboss.resteasy.spi.ResteasyProviderFactory and org.jboss.resteasy.spi.Registry. (Really the string FQN of these classes). There is also a org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware, that will automatically inject references to the Registry and ResteasyProviderFactory from the Servlet Context. (that is, if you have used RestasyBootstrap to bootstrap Resteasy).

有谁知道如何在不使用 Resteasy ContextLoaderListener 的情况下实现这一目标?我需要在 spring applicationContext xml 文件中放入什么?

最佳答案

我也遇到了 RestEasy SpringContextListener 的问题(属性占位符 ${...} 未处理 - RESTEASY-787 ,Spring java 配置没有工作等)。
因此,删除 RestEasy SpringContextListener 并使用默认的 org.springframework.web.context.ContextLoaderListener 或任何您需要的监听器就足够了。您只需在 Spring XML 配置中定义 Spring bean,如下所示:

<bean class="org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware"/>

即使没有特殊的SpringContextListener,RestEasy 也应该可以工作。它对我有用。

关于spring - Resteasy 和 Spring 集成,无需 Spring ContextLoadListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17656186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com