【问题标题】:Wire an existing spring ApplicationContext to REST service with JAX-RS使用 JAX-RS 将现有的 spring ApplicationContext 连接到 REST 服务
【发布时间】:2014-10-31 03:05:40
【问题描述】:

我可以毫无问题地使用暴露的 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>

【问题讨论】:

    标签: java spring rest jetty resteasy


    【解决方案1】:

    我认为你必须将你的服务接口打包为一个单独的 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>
    

    【讨论】:

      猜你喜欢
      • 2013-02-17
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多