java - 使用 Maven 连接多个独立的 Spring 应用程序

标签 java xml spring maven applicationcontext

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

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

每个服务都对内部其他 Bean 有多个依赖关系,因此每个服务都有一个 applicationContext.xml 将服务连接在一起。

我将每个子项目都设为独立的 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 应用程序内部,子服务的所有接线都丢失了。我猜子服务不是使用子服务 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?

最佳答案

您需要包含这些服务中的 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" />

关于java - 使用 Maven 连接多个独立的 Spring 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10519622/

相关文章:

Java欧元符号转换为货币符号

如果发生故障,Spring Kafka自动提交偏移

java - Spring-Boot 部署——JBAS011555 : Failed to configure logging using 'logging.properties' configuration file

java - Python Server/Java客户端“连接被拒绝:连接”

带返回值的对象内的java线程方法

xml - 在 Visual Basic 中将数据添加到 XML 文件的节点

php - 用于 PHP 的 JAXB(PAXB?)

java - 是否可以加快 Maven Artifact 的下载速度?

带有 xml 的 Android 自定义插值器

java - 如何在jdbc模板中实现RowMapper