Wiring multiple independent Spring Applications using Maven

大憨熊 提交于 2019-12-24 01:53:53

问题


My project consists of multiple Spring subprojects:

  • Service1
  • Service2
  • Service3

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

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

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>

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.

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>

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?


回答1:


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" />



回答2:


use classpath*:/META-INF/spring/*-context.xml

References:

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


来源:https://stackoverflow.com/questions/10519622/wiring-multiple-independent-spring-applications-using-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!