[英]Wire an existing spring ApplicationContext to REST service with JAX-RS
I could start my application with REST endpoints exposed without problem. 我可以使用没有问题的REST端点启动我的应用程序。 However, I have another spring ApplicationContext created elsewhere and would like to be accessible from my REST endpoints. 但是,我在其他地方创建了另一个spring ApplicationContext,希望可以从我的REST端点进行访问。
Currently, I have to use a Singleton to lookup the beans. 当前,我必须使用Singleton查找bean。 But is there a way to wire an existing ApplicationContext? 但是,有没有一种方法可以连接现有的ApplicationContext?
Below is what I have. 以下是我所拥有的。
web.xml web.xml
<web-app>
<context-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>package1.MyJaxRsApplication</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
applicationContext.xml applicationContext.xml
<beans>
<context:component-scan base-package="package2.rest" />
</beans>
I think u will have to package your service interfaces as a separate jar and use it on other application. 我认为您将必须将服务接口打包为单独的jar,并在其他应用程序上使用它。 Together with that you will have to define service consuming spring configuration use it in you other application 除此之外,您还必须定义消耗服务的Spring配置,并在其他应用程序中使用它
<bean name="/ExposedService.htm" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="exposedService"/>
<property name="serviceInterface" value="com.app.client.ExposedService"/>
</bean>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.