diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 23feed96924..669df6b31ef 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -51,6 +51,7 @@ import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.support.StandardServletEnvironment; @@ -135,9 +136,9 @@ public class SpringApplication { private final Log log = LogFactory.getLog(getClass()); - private Set defaultSources = new LinkedHashSet(); + private Set sources = new LinkedHashSet(); - private Set additionalSources = new LinkedHashSet(); + private Set initialSources = new LinkedHashSet(); private Class mainApplicationClass; @@ -193,7 +194,7 @@ public class SpringApplication { private void initialize(Object[] sources) { if (sources != null && sources.length > 0) { - this.additionalSources.addAll(Arrays.asList(sources)); + this.initialSources.addAll(Arrays.asList(sources)); } this.webEnvironment = deduceWebEnvironment(); this.initializers = new ArrayList>(); @@ -275,8 +276,8 @@ public class SpringApplication { private Set assembleSources() { LinkedHashSet sources = new LinkedHashSet(); - sources.addAll(this.defaultSources); - sources.addAll(this.additionalSources); + sources.addAll(this.sources); + sources.addAll(this.initialSources); return sources; } @@ -360,9 +361,6 @@ public class SpringApplication { protected void logStartupInfo() { Log applicationLog = getApplicationLog(); new StartupInfoLogger(this.mainApplicationClass).log(applicationLog); - if (applicationLog.isDebugEnabled()) { - applicationLog.debug("Sources: " + this.defaultSources); - } } /** @@ -434,6 +432,10 @@ public class SpringApplication { * @param sources the sources to load */ protected void load(ApplicationContext context, Object[] sources) { + if (this.log.isDebugEnabled()) { + this.log.debug("Loading source " + + StringUtils.arrayToCommaDelimitedString(sources)); + } BeanDefinitionLoader loader = createBeanDefinitionLoader( getBeanDefinitionRegistry(context), sources); if (this.beanNameGenerator != null) { @@ -574,7 +576,7 @@ public class SpringApplication { * @see #SpringApplication(Object...) */ public Set getSources() { - return this.defaultSources; + return this.sources; } /** @@ -582,12 +584,15 @@ public class SpringApplication { * one of: a class, class name, package, package name, or an XML resource location. * Can also be set using constructors and static convenience methods (e.g. * {@link #run(Object[], String[])}). + *

+ * NOTE: sources defined here will be used in addition to any sources specified on + * construction. * @param sources the sources to set * @see #SpringApplication(Object...) */ public void setSources(Set sources) { Assert.notNull(sources, "Sources must not be null"); - this.defaultSources = new LinkedHashSet(sources); + this.sources = new LinkedHashSet(sources); } /** diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 8bb6ba989f2..b8769692d40 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -271,9 +271,9 @@ public class SpringApplicationTests { application.setUseMockLoader(true); application.run(); @SuppressWarnings("unchecked") - Set additionalSources = (Set) ReflectionTestUtils.getField( - application, "additionalSources"); - assertThat(additionalSources.toArray(), equalTo(sources)); + Set initialSources = (Set) ReflectionTestUtils.getField( + application, "initialSources"); + assertThat(initialSources.toArray(), equalTo(sources)); } @Test