繁体   English   中英

使用JAX-RS将现有的Spring ApplicationContext连接到REST服务

[英]Wire an existing spring ApplicationContext to REST service with JAX-RS

我可以使用没有问题的REST端点启动我的应用程序。 但是,我在其他地方创建了另一个spring 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,并在其他应用程序上使用它。 除此之外,您还必须定义消耗服务的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM