parent
e9c69aa46f
commit
133304c4f7
|
|
@ -77,38 +77,38 @@ import org.springframework.web.context.support.StandardServletEnvironment;
|
||||||
* Classes that can be used to bootstrap and launch a Spring application from a Java main
|
* Classes that can be used to bootstrap and launch a Spring application from a Java main
|
||||||
* method. By default class will perform the following steps to bootstrap your
|
* method. By default class will perform the following steps to bootstrap your
|
||||||
* application:
|
* application:
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Create an appropriate {@link ApplicationContext} instance (depending on your
|
* <li>Create an appropriate {@link ApplicationContext} instance (depending on your
|
||||||
* classpath)</li>
|
* classpath)</li>
|
||||||
*
|
*
|
||||||
* <li>Register a {@link CommandLinePropertySource} to expose command line arguments as
|
* <li>Register a {@link CommandLinePropertySource} to expose command line arguments as
|
||||||
* Spring properties</li>
|
* Spring properties</li>
|
||||||
*
|
*
|
||||||
* <li>Refresh the application context, loading all singleton beans</li>
|
* <li>Refresh the application context, loading all singleton beans</li>
|
||||||
*
|
*
|
||||||
* <li>Trigger any {@link CommandLineRunner} beans</li>
|
* <li>Trigger any {@link CommandLineRunner} beans</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* In most circumstances the static {@link #run(Object, String[])} method can be called
|
* In most circumstances the static {@link #run(Object, String[])} method can be called
|
||||||
* directly from your {@literal main} method to bootstrap your application:
|
* directly from your {@literal main} method to bootstrap your application:
|
||||||
*
|
*
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* @Configuration
|
* @Configuration
|
||||||
* @EnableAutoConfiguration
|
* @EnableAutoConfiguration
|
||||||
* public class MyApplication {
|
* public class MyApplication {
|
||||||
*
|
*
|
||||||
* // ... Bean definitions
|
* // ... Bean definitions
|
||||||
*
|
*
|
||||||
* public static void main(String[] args) throws Exception {
|
* public static void main(String[] args) throws Exception {
|
||||||
* SpringApplication.run(MyApplication.class, args);
|
* SpringApplication.run(MyApplication.class, args);
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* For more advanced configuration a {@link SpringApplication} instance can be created and
|
* For more advanced configuration a {@link SpringApplication} instance can be created and
|
||||||
* customized before being run:
|
* customized before being run:
|
||||||
*
|
*
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* public static void main(String[] args) throws Exception {
|
* public static void main(String[] args) throws Exception {
|
||||||
* SpringApplication app = new SpringApplication(MyApplication.class);
|
* SpringApplication app = new SpringApplication(MyApplication.class);
|
||||||
|
|
@ -116,29 +116,30 @@ import org.springframework.web.context.support.StandardServletEnvironment;
|
||||||
* app.run(args)
|
* app.run(args)
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* {@link SpringApplication}s can read beans from a variety of different sources. It is
|
* {@link SpringApplication}s can read beans from a variety of different sources. It is
|
||||||
* generally recommended that a single {@code @Configuration} class is used to bootstrap
|
* generally recommended that a single {@code @Configuration} class is used to bootstrap
|
||||||
* your application, however, any of the following sources can also be used:
|
* your application, however, any of the following sources can also be used:
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link Class} - A Java class to be loaded by {@link AnnotatedBeanDefinitionReader}</li>
|
* <li>{@link Class} - A Java class to be loaded by {@link AnnotatedBeanDefinitionReader}</li>
|
||||||
*
|
*
|
||||||
* <li>{@link Resource} - An XML resource to be loaded by {@link XmlBeanDefinitionReader},
|
* <li>{@link Resource} - An XML resource to be loaded by {@link XmlBeanDefinitionReader},
|
||||||
* or a groovy script to be loaded by {@link GroovyBeanDefinitionReader}</li>
|
* or a groovy script to be loaded by {@link GroovyBeanDefinitionReader}</li>
|
||||||
*
|
*
|
||||||
* <li>{@link Package} - A Java package to be scanned by
|
* <li>{@link Package} - A Java package to be scanned by
|
||||||
* {@link ClassPathBeanDefinitionScanner}</li>
|
* {@link ClassPathBeanDefinitionScanner}</li>
|
||||||
*
|
*
|
||||||
* <li>{@link CharSequence} - A class name, resource handle or package name to loaded as
|
* <li>{@link CharSequence} - A class name, resource handle or package name to loaded as
|
||||||
* appropriate. If the {@link CharSequence} cannot be resolved to class and does not
|
* appropriate. If the {@link CharSequence} cannot be resolved to class and does not
|
||||||
* resolve to a {@link Resource} that exists it will be considered a {@link Package}.</li>
|
* resolve to a {@link Resource} that exists it will be considered a {@link Package}.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Christian Dupuis
|
||||||
* @see #run(Object, String[])
|
* @see #run(Object, String[])
|
||||||
* @see #run(Object[], String[])
|
* @see #run(Object[], String[])
|
||||||
* @see #SpringApplication(Object...)
|
* @see #SpringApplication(Object...)
|
||||||
|
|
@ -152,7 +153,7 @@ public class SpringApplication {
|
||||||
+ "boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext";
|
+ "boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext";
|
||||||
|
|
||||||
private static final String[] WEB_ENVIRONMENT_CLASSES = { "javax.servlet.Servlet",
|
private static final String[] WEB_ENVIRONMENT_CLASSES = { "javax.servlet.Servlet",
|
||||||
"org.springframework.web.context.ConfigurableWebApplicationContext" };
|
"org.springframework.web.context.ConfigurableWebApplicationContext" };
|
||||||
|
|
||||||
private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless";
|
private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless";
|
||||||
|
|
||||||
|
|
@ -478,10 +479,11 @@ public class SpringApplication {
|
||||||
Resource resource = resourceLoader.getResource(location);
|
Resource resource = resourceLoader.getResource(location);
|
||||||
if (resource.exists()) {
|
if (resource.exists()) {
|
||||||
try {
|
try {
|
||||||
System.out.println(StreamUtils.copyToString(
|
String banner = StreamUtils.copyToString(
|
||||||
resource.getInputStream(),
|
resource.getInputStream(),
|
||||||
environment.getProperty("banner.charset", Charset.class,
|
environment.getProperty("banner.charset", Charset.class,
|
||||||
Charset.forName("UTF-8"))));
|
Charset.forName("UTF-8")));
|
||||||
|
System.out.println(environment.resolvePlaceholders(banner));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
|
@ -546,7 +548,7 @@ public class SpringApplication {
|
||||||
if (this.resourceLoader != null) {
|
if (this.resourceLoader != null) {
|
||||||
if (context instanceof GenericApplicationContext) {
|
if (context instanceof GenericApplicationContext) {
|
||||||
((GenericApplicationContext) context)
|
((GenericApplicationContext) context)
|
||||||
.setResourceLoader(this.resourceLoader);
|
.setResourceLoader(this.resourceLoader);
|
||||||
}
|
}
|
||||||
if (context instanceof DefaultResourceLoader) {
|
if (context instanceof DefaultResourceLoader) {
|
||||||
((DefaultResourceLoader) context).setClassLoader(this.resourceLoader
|
((DefaultResourceLoader) context).setClassLoader(this.resourceLoader
|
||||||
|
|
@ -579,7 +581,7 @@ public class SpringApplication {
|
||||||
protected void logStartupInfo(boolean isRoot) {
|
protected void logStartupInfo(boolean isRoot) {
|
||||||
if (isRoot) {
|
if (isRoot) {
|
||||||
new StartupInfoLogger(this.mainApplicationClass)
|
new StartupInfoLogger(this.mainApplicationClass)
|
||||||
.logStarting(getApplicationLog());
|
.logStarting(getApplicationLog());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,11 @@ import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link SpringApplication}.
|
* Tests for {@link SpringApplication}.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Christian Dupuis
|
||||||
*/
|
*/
|
||||||
public class SpringApplicationTests {
|
public class SpringApplicationTests {
|
||||||
|
|
||||||
|
|
@ -162,6 +163,15 @@ public class SpringApplicationTests {
|
||||||
verify(application, never()).printBanner();
|
verify(application, never()).printBanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customBannerWithProperties() throws Exception {
|
||||||
|
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
|
||||||
|
application.setWebEnvironment(false);
|
||||||
|
application.run("--banner.location=classpath:test-banner-with-placeholder.txt",
|
||||||
|
"--test.property=123456");
|
||||||
|
verify(application, never()).printBanner();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customId() throws Exception {
|
public void customId() throws Exception {
|
||||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
Running a Test!
|
||||||
|
|
||||||
|
${test.property}
|
||||||
Loading…
Reference in New Issue