77
77
* Classes that can be used to bootstrap and launch a Spring application from a Java main
78
78
* method. By default class will perform the following steps to bootstrap your
79
79
* application:
80
- *
80
+ *
81
81
* <ul>
82
82
* <li>Create an appropriate {@link ApplicationContext} instance (depending on your
83
83
* classpath)</li>
84
- *
84
+ *
85
85
* <li>Register a {@link CommandLinePropertySource} to expose command line arguments as
86
86
* Spring properties</li>
87
- *
87
+ *
88
88
* <li>Refresh the application context, loading all singleton beans</li>
89
- *
89
+ *
90
90
* <li>Trigger any {@link CommandLineRunner} beans</li>
91
91
* </ul>
92
- *
92
+ *
93
93
* In most circumstances the static {@link #run(Object, String[])} method can be called
94
94
* directly from your {@literal main} method to bootstrap your application:
95
- *
95
+ *
96
96
* <pre class="code">
97
97
* @Configuration
98
98
* @EnableAutoConfiguration
99
99
* public class MyApplication {
100
- *
100
+ *
101
101
* // ... Bean definitions
102
- *
102
+ *
103
103
* public static void main(String[] args) throws Exception {
104
104
* SpringApplication.run(MyApplication.class, args);
105
105
* }
106
106
* </pre>
107
- *
107
+ *
108
108
* <p>
109
109
* For more advanced configuration a {@link SpringApplication} instance can be created and
110
110
* customized before being run:
111
- *
111
+ *
112
112
* <pre class="code">
113
113
* public static void main(String[] args) throws Exception {
114
114
* SpringApplication app = new SpringApplication(MyApplication.class);
115
115
* // ... customize app settings here
116
116
* app.run(args)
117
117
* }
118
118
* </pre>
119
- *
119
+ *
120
120
* {@link SpringApplication}s can read beans from a variety of different sources. It is
121
121
* generally recommended that a single {@code @Configuration} class is used to bootstrap
122
122
* your application, however, any of the following sources can also be used:
123
- *
123
+ *
124
124
* <p>
125
125
* <ul>
126
126
* <li>{@link Class} - A Java class to be loaded by {@link AnnotatedBeanDefinitionReader}</li>
127
- *
127
+ *
128
128
* <li>{@link Resource} - An XML resource to be loaded by {@link XmlBeanDefinitionReader},
129
129
* or a groovy script to be loaded by {@link GroovyBeanDefinitionReader}</li>
130
- *
130
+ *
131
131
* <li>{@link Package} - A Java package to be scanned by
132
132
* {@link ClassPathBeanDefinitionScanner}</li>
133
- *
133
+ *
134
134
* <li>{@link CharSequence} - A class name, resource handle or package name to loaded as
135
135
* appropriate. If the {@link CharSequence} cannot be resolved to class and does not
136
136
* resolve to a {@link Resource} that exists it will be considered a {@link Package}.</li>
137
137
* </ul>
138
- *
138
+ *
139
139
* @author Phillip Webb
140
140
* @author Dave Syer
141
+ * @author Andy Wilkinson
141
142
* @see #run(Object, String[])
142
143
* @see #run(Object[], String[])
143
144
* @see #SpringApplication(Object...)
@@ -151,7 +152,9 @@ public class SpringApplication {
151
152
+ "boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext" ;
152
153
153
154
private static final String [] WEB_ENVIRONMENT_CLASSES = { "javax.servlet.Servlet" ,
154
- "org.springframework.web.context.ConfigurableWebApplicationContext" };
155
+ "org.springframework.web.context.ConfigurableWebApplicationContext" };
156
+
157
+ private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless" ;
155
158
156
159
private final Log log = LogFactory .getLog (getClass ());
157
160
@@ -262,7 +265,10 @@ public ConfigurableApplicationContext run(String... args) {
262
265
stopWatch .start ();
263
266
ConfigurableApplicationContext context = null ;
264
267
265
- System .setProperty ("java.awt.headless" , Boolean .toString (this .headless ));
268
+ System .setProperty (
269
+ SYSTEM_PROPERTY_JAVA_AWT_HEADLESS ,
270
+ System .getProperty (SYSTEM_PROPERTY_JAVA_AWT_HEADLESS ,
271
+ Boolean .toString (this .headless )));
266
272
267
273
Collection <SpringApplicationRunListener > runListeners = getRunListeners (args );
268
274
for (SpringApplicationRunListener runListener : runListeners ) {
@@ -540,7 +546,7 @@ protected void postProcessApplicationContext(ConfigurableApplicationContext cont
540
546
if (this .resourceLoader != null ) {
541
547
if (context instanceof GenericApplicationContext ) {
542
548
((GenericApplicationContext ) context )
543
- .setResourceLoader (this .resourceLoader );
549
+ .setResourceLoader (this .resourceLoader );
544
550
}
545
551
if (context instanceof DefaultResourceLoader ) {
546
552
((DefaultResourceLoader ) context ).setClassLoader (this .resourceLoader
@@ -573,7 +579,7 @@ protected void applyInitializers(ConfigurableApplicationContext context) {
573
579
protected void logStartupInfo (boolean isRoot ) {
574
580
if (isRoot ) {
575
581
new StartupInfoLogger (this .mainApplicationClass )
576
- .logStarting (getApplicationLog ());
582
+ .logStarting (getApplicationLog ());
577
583
}
578
584
}
579
585
0 commit comments