You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/06/16 15:47:50 UTC
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
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 <da...@apache.org>
Authored: Mon Jun 16 15:34:52 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
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<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;
}