【问题标题】:Wiring multiple independent Spring Applications using Maven使用 Maven 连接多个独立的 Spring 应用程序
【发布时间】:2012-05-18 04:14:40
【问题描述】:

我的项目由多个 Spring 子项目组成:

  • 服务1
  • 服务2
  • 服务3

每个 Service 对内部的其他 Bean 都有多个依赖项,因此每个 Service 都有一个 applicationContext.xml 将 Service 连接在一起。

我将每个子项目都制作为独立的 maven 构建,我认为我可以创建一个 AllServicesTogether 应用程序来将这些服务{1..3} 连接在一起。

这通过向这些服务添加 maven 依赖项来工作。

<dependencies>
    <dependency>
        <groupId>org.myproject</groupId>
        <artifactId>myproject-service{1..3}</artifactId>
        <version>0.1-SNAPSHOT</version>
    </dependency>
    ...
</dependencies>

但是在 AllServicesTogether 应用程序中,所有子服务的连接都丢失了。我猜 Subservices 不是用 Subservice ApplicationContext 编译的,而是使用 AllServicesTogether ApplicationContext。

这个想法是封装 SubSerivces 的所有接线,并使用以下方法简单地连接 AllServicesTogether:

<beans ..>
    <bean class="org.myproject.service1.Service1"/>
    <bean class="org.myproject.service1.Service2"/>
    <bean class="org.myproject.service1.Service3"/>
</beans>

我从花费数小时的较大项目中创建了这些子项目。 是否可以使用这种接线方法,还是我需要包含所有这些服务中的 context.xml?

【问题讨论】:

    标签: java xml spring maven applicationcontext


    【解决方案1】:

    使用类路径*:/META-INF/spring/*-context.xml

    参考文献:

    1. Spring application context loading tricks
    2. Spring ApplicationContext with multiple XML Files from Jar

    【讨论】:

      【解决方案2】:

      您需要包含来自这些服务的 context.xml。最好在 AllServicesTogether-context.xml 中使用“导入”来完成:

      <import resource="classpath*:/META-INF/spring/service1-context.xml" />
      <import resource="classpath*:/META-INF/spring/service2-context.xml" />
      <import resource="classpath*:/META-INF/spring/service3-context.xml" />
      

      【讨论】:

      • 谢谢你。这只有在我可以明确告诉服务时才有效,但它有效。我需要它来处理大量文件并尝试使用模式匹配,另请参阅我更详细的方法:link
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 2012-03-29
      • 2013-09-22
      • 2014-01-29
      相关资源
      最近更新 更多