Browse Source

AbstractApplicationContext can also start up in case of system properties access failure

pull/23217/head
Juergen Hoeller 15 years ago
parent
commit
a62068461f
  1. 27
      org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

27
org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -18,13 +18,16 @@ package org.springframework.context.support;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.security.AccessControlException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -468,10 +471,30 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Register default environment beans. // Register default environment beans.
if (!beanFactory.containsBean(SYSTEM_PROPERTIES_BEAN_NAME)) { if (!beanFactory.containsBean(SYSTEM_PROPERTIES_BEAN_NAME)) {
beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, System.getProperties()); Properties systemProperties;
try {
systemProperties = System.getProperties();
}
catch (AccessControlException ex) {
if (logger.isInfoEnabled()) {
logger.info("Not allowed to obtain system properties: " + ex.getMessage());
}
systemProperties = new Properties();
}
beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, systemProperties);
} }
if (!beanFactory.containsBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) { if (!beanFactory.containsBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) {
beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, System.getenv()); Map<String,String> systemEnvironment;
try {
systemEnvironment = System.getenv();
}
catch (AccessControlException ex) {
if (logger.isInfoEnabled()) {
logger.info("Not allowed to obtain system environment: " + ex.getMessage());
}
systemEnvironment = Collections.emptyMap();
}
beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, systemEnvironment);
} }
} }

Loading…
Cancel
Save