簡體   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