mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
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
This commit is contained in:
parent
3fda19af58
commit
88bc6c0b56
@ -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 {
|
|||||||
|
|
||||||
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 {
|
|||||||
|
|
||||||
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 {
|
|||||||
|
|
||||||
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 {
|
|||||||
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 {
|
|||||||
* @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 {
|
|||||||
* @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 {
|
|||||||
* 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 {
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user