From a62068461fb5fdfbd740a61a5cb8a0b972f98fda Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 7 Nov 2009 01:09:02 +0000 Subject: [PATCH] AbstractApplicationContext can also start up in case of system properties access failure --- .../support/AbstractApplicationContext.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index 2dd86e26d9..93db7d2559 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/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.lang.annotation.Annotation; +import java.security.AccessControlException; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -468,10 +471,30 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader // Register default environment beans. 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)) { - beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, System.getenv()); + Map 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); } }