Repository: camel Updated Branches: refs/heads/master bd4f8d1e8 -> 9f90b0274
CAMEL-7361: Spring main should be able to detect additional spring xml locations on the classpath without any additional configuration. Use a different location as META-INF/spring clashes with Spring itself and causes it to not be able to discover and XML files in classpath, depeding on the order of the JARs on the classpath. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9f90b027 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9f90b027 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9f90b027 Branch: refs/heads/master Commit: 9f90b0274f2dc291b58064278cf060a68b176dff Parents: bd4f8d1 Author: Claus Ibsen <[email protected]> Authored: Mon Jun 16 15:34:52 2014 +0200 Committer: Claus Ibsen <[email protected]> Committed: Mon Jun 16 15:47:57 2014 +0200 ---------------------------------------------------------------------- .../main/java/org/apache/camel/spring/Main.java | 33 +++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9f90b027/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java b/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java index a09e8d4..23475ca 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java @@ -54,7 +54,7 @@ import org.springframework.context.support.FileSystemXmlApplicationContext; @SuppressWarnings("deprecation") public class Main extends MainSupport { - public static final String LOCATION_PROPERTIES = "META-INF/spring/location.properties"; + public static final String LOCATION_PROPERTIES = "META-INF/camel-spring/location.properties"; protected static Main instance; private static final Charset UTF8 = Charset.forName("UTF-8"); @@ -62,6 +62,7 @@ public class Main extends MainSupport { private String fileApplicationContextUri; private AbstractApplicationContext applicationContext; private AbstractApplicationContext parentApplicationContext; + private AbstractApplicationContext additionalApplicationContext; private String parentApplicationContextUri; public Main() { @@ -155,6 +156,16 @@ public class Main extends MainSupport { if (applicationContext == null) { applicationContext = createDefaultApplicationContext(); } + + // then start any additional after Camel has been started + if (additionalApplicationContext == null) { + additionalApplicationContext = createAdditionalLocationsFromClasspath(); + if (additionalApplicationContext != null) { + LOG.debug("Starting Additional ApplicationContext: " + additionalApplicationContext.getId()); + additionalApplicationContext.start(); + } + } + LOG.debug("Starting Spring ApplicationContext: " + applicationContext.getId()); applicationContext.start(); @@ -163,6 +174,10 @@ public class Main extends MainSupport { protected void doStop() throws Exception { super.doStop(); + if (additionalApplicationContext != null) { + LOG.debug("Stopping Additional ApplicationContext: " + additionalApplicationContext.getId()); + IOHelper.close(additionalApplicationContext); + } if (applicationContext != null) { LOG.debug("Stopping Spring ApplicationContext: " + applicationContext.getId()); IOHelper.close(applicationContext); @@ -181,9 +196,7 @@ public class Main extends MainSupport { } protected AbstractApplicationContext createDefaultApplicationContext() throws IOException { - // daisy chain the parent and additional contexts ApplicationContext parentContext = getParentApplicationContext(); - parentContext = addAdditionalLocationsFromClasspath(parentContext); // file based if (getFileApplicationContextUri() != null) { @@ -221,9 +234,7 @@ public class Main extends MainSupport { return new ModelFileGenerator(new CamelNamespaceHandler().getJaxbContext()); } - protected ApplicationContext addAdditionalLocationsFromClasspath(ApplicationContext parentContext) throws IOException { - StringBuilder sb = new StringBuilder(); - + protected AbstractApplicationContext createAdditionalLocationsFromClasspath() throws IOException { Set<String> locations = new LinkedHashSet<String>(); findLocations(locations, Main.class.getClassLoader()); @@ -231,15 +242,7 @@ public class Main extends MainSupport { LOG.info("Found locations for additional Spring XML files: {}", locations); String[] locs = locations.toArray(new String[locations.size()]); - ClassPathXmlApplicationContext additionalContext; - if (parentContext != null) { - additionalContext = new ClassPathXmlApplicationContext(locs, parentContext); - } else { - additionalContext = new ClassPathXmlApplicationContext(locs); - } - // and we must start the app context as well - additionalContext.start(); - return additionalContext; + return new ClassPathXmlApplicationContext(locs); } else { return null; }
