@ -138,6 +138,7 @@ import org.springframework.web.context.support.StandardServletEnvironment;
* @author Dave Syer
* @author Andy Wilkinson
* @author Christian Dupuis
* @author Stephane Nicoll
* @see # run ( Object , String [ ] )
* @see # run ( Object [ ] , String [ ] )
* @see # SpringApplication ( Object . . . )
@ -226,21 +227,12 @@ public class SpringApplication {
if ( sources ! = null & & sources . length > 0 ) {
this . sources . addAll ( Arrays . asList ( sources ) ) ;
}
this . webEnvironment = deduceWebEnvironment ( ) ;
this . webEnvironment = isSpringWebAvailable ( ) ;
setInitializers ( ( Collection ) getSpringFactoriesInstances ( ApplicationContextInitializer . class ) ) ;
setListeners ( ( Collection ) getSpringFactoriesInstances ( ApplicationListener . class ) ) ;
this . mainApplicationClass = deduceMainApplicationClass ( ) ;
}
private boolean deduceWebEnvironment ( ) {
for ( String className : WEB_ENVIRONMENT_CLASSES ) {
if ( ! ClassUtils . isPresent ( className , null ) ) {
return false ;
}
}
return true ;
}
private Class < ? > deduceMainApplicationClass ( ) {
try {
StackTraceElement [ ] stackTrace = new RuntimeException ( ) . getStackTrace ( ) ;
@ -872,7 +864,8 @@ public class SpringApplication {
public void setApplicationContextClass (
Class < ? extends ConfigurableApplicationContext > applicationContextClass ) {
this . applicationContextClass = applicationContextClass ;
if ( ! WebApplicationContext . class . isAssignableFrom ( applicationContextClass ) ) {
if ( isSpringWebAvailable ( ) & & ! WebApplicationContext . class . isAssignableFrom (
applicationContextClass ) ) {
this . webEnvironment = false ;
}
}
@ -935,6 +928,15 @@ public class SpringApplication {
return asUnmodifiableOrderedSet ( this . listeners ) ;
}
private boolean isSpringWebAvailable ( ) {
for ( String className : WEB_ENVIRONMENT_CLASSES ) {
if ( ! ClassUtils . isPresent ( className , null ) ) {
return false ;
}
}
return true ;
}
/ * *
* Static helper that can be used to run a { @link SpringApplication } from the
* specified source using default settings .