我的项目由多个 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/