Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6AD3F117B6 for ; Mon, 16 Jun 2014 13:47:51 +0000 (UTC) Received: (qmail 90300 invoked by uid 500); 16 Jun 2014 13:47:51 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 90248 invoked by uid 500); 16 Jun 2014 13:47:51 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 90239 invoked by uid 99); 16 Jun 2014 13:47:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jun 2014 13:47:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F19D294034C; Mon, 16 Jun 2014 13:47:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Message-Id: <16a717a5d3c843cd89e8049cf098ffa9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: 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 dis Date: Mon, 16 Jun 2014 13:47:50 +0000 (UTC) Repository: camel Updated Branches: refs/heads/camel-2.13.x 698343e1b -> e72ea3579 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/e72ea357 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e72ea357 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e72ea357 Branch: refs/heads/camel-2.13.x Commit: e72ea3579b6de2a5f7f89191dc9462b0b3566af1 Parents: 698343e Author: Claus Ibsen Authored: Mon Jun 16 15:34:52 2014 +0200 Committer: Claus Ibsen Committed: Mon Jun 16 15:45:35 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/e72ea357/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 locations = new LinkedHashSet(); 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; }