Commit 88bc6c0b authored by Phillip Webb's avatar Phillip Webb

Update Javadoc following source logic change

Update Javadoc to indicate the sources are used in addition to those
specified on construction. Also renamed member variables and fixed
log output.

Issue: #54185750
parent 3fda19af
...@@ -51,6 +51,7 @@ import org.springframework.core.io.ResourceLoader; ...@@ -51,6 +51,7 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.support.StandardServletEnvironment; import org.springframework.web.context.support.StandardServletEnvironment;
...@@ -135,9 +136,9 @@ public class SpringApplication { ...@@ -135,9 +136,9 @@ public class SpringApplication {
private final Log log = LogFactory.getLog(getClass()); private final Log log = LogFactory.getLog(getClass());
private Set<Object> defaultSources = new LinkedHashSet<Object>(); private Set<Object> sources = new LinkedHashSet<Object>();
private Set<Object> additionalSources = new LinkedHashSet<Object>(); private Set<Object> initialSources = new LinkedHashSet<Object>();
private Class<?> mainApplicationClass; private Class<?> mainApplicationClass;
...@@ -193,7 +194,7 @@ public class SpringApplication { ...@@ -193,7 +194,7 @@ public class SpringApplication {
private void initialize(Object[] sources) { private void initialize(Object[] sources) {
if (sources != null && sources.length > 0) { if (sources != null && sources.length > 0) {
this.additionalSources.addAll(Arrays.asList(sources)); this.initialSources.addAll(Arrays.asList(sources));
} }
this.webEnvironment = deduceWebEnvironment(); this.webEnvironment = deduceWebEnvironment();
this.initializers = new ArrayList<ApplicationContextInitializer<?>>(); this.initializers = new ArrayList<ApplicationContextInitializer<?>>();
...@@ -275,8 +276,8 @@ public class SpringApplication { ...@@ -275,8 +276,8 @@ public class SpringApplication {
private Set<Object> assembleSources() { private Set<Object> assembleSources() {
LinkedHashSet<Object> sources = new LinkedHashSet<Object>(); LinkedHashSet<Object> sources = new LinkedHashSet<Object>();
sources.addAll(this.defaultSources); sources.addAll(this.sources);
sources.addAll(this.additionalSources); sources.addAll(this.initialSources);
return sources; return sources;
} }
...@@ -360,9 +361,6 @@ public class SpringApplication { ...@@ -360,9 +361,6 @@ public class SpringApplication {
protected void logStartupInfo() { protected void logStartupInfo() {
Log applicationLog = getApplicationLog(); Log applicationLog = getApplicationLog();
new StartupInfoLogger(this.mainApplicationClass).log(applicationLog); new StartupInfoLogger(this.mainApplicationClass).log(applicationLog);
if (applicationLog.isDebugEnabled()) {
applicationLog.debug("Sources: " + this.defaultSources);
}
} }
/** /**
...@@ -434,6 +432,10 @@ public class SpringApplication { ...@@ -434,6 +432,10 @@ public class SpringApplication {
* @param sources the sources to load * @param sources the sources to load
*/ */
protected void load(ApplicationContext context, Object[] sources) { protected void load(ApplicationContext context, Object[] sources) {
if (this.log.isDebugEnabled()) {
this.log.debug("Loading source "
+ StringUtils.arrayToCommaDelimitedString(sources));
}
BeanDefinitionLoader loader = createBeanDefinitionLoader( BeanDefinitionLoader loader = createBeanDefinitionLoader(
getBeanDefinitionRegistry(context), sources); getBeanDefinitionRegistry(context), sources);
if (this.beanNameGenerator != null) { if (this.beanNameGenerator != null) {
...@@ -574,7 +576,7 @@ public class SpringApplication { ...@@ -574,7 +576,7 @@ public class SpringApplication {
* @see #SpringApplication(Object...) * @see #SpringApplication(Object...)
*/ */
public Set<Object> getSources() { public Set<Object> getSources() {
return this.defaultSources; return this.sources;
} }
/** /**
...@@ -582,12 +584,15 @@ public class SpringApplication { ...@@ -582,12 +584,15 @@ public class SpringApplication {
* one of: a class, class name, package, package name, or an XML resource location. * 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. * Can also be set using constructors and static convenience methods (e.g.
* {@link #run(Object[], String[])}). * {@link #run(Object[], String[])}).
* <p>
* NOTE: sources defined here will be used in addition to any sources specified on
* construction.
* @param sources the sources to set * @param sources the sources to set
* @see #SpringApplication(Object...) * @see #SpringApplication(Object...)
*/ */
public void setSources(Set<Object> sources) { public void setSources(Set<Object> sources) {
Assert.notNull(sources, "Sources must not be null"); Assert.notNull(sources, "Sources must not be null");
this.defaultSources = new LinkedHashSet<Object>(sources); this.sources = new LinkedHashSet<Object>(sources);
} }
/** /**
......
...@@ -271,9 +271,9 @@ public class SpringApplicationTests { ...@@ -271,9 +271,9 @@ public class SpringApplicationTests {
application.setUseMockLoader(true); application.setUseMockLoader(true);
application.run(); application.run();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Set<Object> additionalSources = (Set<Object>) ReflectionTestUtils.getField( Set<Object> initialSources = (Set<Object>) ReflectionTestUtils.getField(
application, "additionalSources"); application, "initialSources");
assertThat(additionalSources.toArray(), equalTo(sources)); assertThat(initialSources.toArray(), equalTo(sources));
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment