2

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?

blang
  • 2,090
  • 2
  • 18
  • 17

2 Answers2

3

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" />
Roy Truelove
  • 22,016
  • 18
  • 111
  • 153
  • Thank you for this. This works only if i can tell the services explicitly, but it works. I need this to work for a big amount of files and try to using pattern matching, please see also my more detailed approach: [link](http://stackoverflow.com/questions/10523945/spring-applicationcontext-with-multiple-xml-files-from-jar) – blang May 09 '12 at 21:00
1

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

References:

  1. Spring application context loading tricks
  2. Spring ApplicationContext with multiple XML Files from Jar
Community
  • 1
  • 1
Hyperion
  • 31
  • 1
  • 4