使用JAX-RS将现有弹簧ApplicationContext连线到REST服务
问题描述:
我可以使用暴露无问题的REST端点来启动我的应用程序。 但是,我在别处创建了另一个Spring ApplicationContext,希望可以从我的REST端点访问它。使用JAX-RS将现有弹簧ApplicationContext连线到REST服务
目前,我不得不使用一个Singleton来查找bean。但有没有办法连接现有的ApplicationContext?
以下是我所拥有的。
的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
<beans>
<context:component-scan base-package="package2.rest" />
</beans>
答
我觉得你将不得不打包服务接口作为一个单独的jar,并用它在其它应用程序。加上你必须定义服务消费弹簧配置使用它在你的其他应用程序
<bean name="/ExposedService.htm" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="exposedService"/>
<property name="serviceInterface" value="com.app.client.ExposedService"/>
</bean>