使用 Maven 连接多个独立的 Spring 应用程序 [英] Wiring multiple independent Spring Applications using Maven

查看:79
本文介绍了使用 Maven 连接多个独立的 Spring 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My project consists of multiple Spring subprojects:

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

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

Every Service has multiple dependencies to other Beans inside, so every Service has an applicationContext.xml wiring the Service together.

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

I made every subproject an standalone maven build and i thought i can create a AllServicesTogether Application to wire those Service{1..3} together.

这是通过向这些服务添加 maven 依赖项来实现的.

This works by adding maven dependencies to those Services.

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

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

But inside the AllServicesTogether Application, all wiring of the SubServices is lost. I guess Subservices aren't compiled with the Subservice ApplicationContext, but use the AllServicesTogether ApplicationContext.

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

The Idea is to encapsulate all wiring of SubSerivces and simply wire the AllServicesTogether by using:

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

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

I created those subprojects from the bigger project spending hours on it. Is it possible to use this wiring method or do i need to include the context.xml's from all those Services?

推荐答案

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

You need to include the context.xml's from those services. This is best done using 'import' in your 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" />

这篇关于使用 Maven 连接多个独立的 Spring 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆