---
title: "Spring读取系统属性的方法就是先读system.getProperty() 然后再读 System.getenv()"
author: "liusu"
date: "2013-03-28T18:15:34Z"
tags: []
categories: ["互联网"]
slug: "spring-system-getproperty-system-getenv"
draft: false
lastmod: "2013-03-28T18:15:12Z"
id: 1838189
url: "https://liusu.iteye.com/blog/1838189"
---

这是整个调用的Stacktrace \[code="java"]\[/code] \[code="java"] Thread \[main] (Suspended) owns: Object (id=22) PropertyPlaceholderConfigurer.resolveSystemProperty(String) line: 358 PropertyPlaceholderConfigurer.resolvePlaceholder(String, Properties, int) line: 324 PropertyPlaceholderConfigurer$PropertyPlaceholderConfigurerResolver.resolvePlaceholder(String) line: 418 PropertyPlaceholderHelper.parseStringValue(String, PlaceholderResolver, Set) line: 146 PropertyPlaceholderHelper.replacePlaceholders(String, PropertyPlaceholderHelper$PlaceholderResolver) line: 125 PropertyPlaceholderConfigurer$PlaceholderResolvingStringValueResolver.resolveStringValue(String) line: 403 BeanDefinitionVisitor.resolveStringValue(String) line: 281 BeanDefinitionVisitor.resolveValue(Object) line: 202 BeanDefinitionVisitor.visitPropertyValues(MutablePropertyValues) line: 140 BeanDefinitionVisitor.visitBeanDefinition(BeanDefinition) line: 81 PropertyPlaceholderConfigurer.processProperties(ConfigurableListableBeanFactory, Properties) line: 284 PropertyPlaceholderConfigurer(PropertyResourceConfigurer).postProcessBeanFactory(ConfigurableListableBeanFactory) line: 75 FileSystemXmlApplicationContext(AbstractApplicationContext).invokeBeanFactoryPostProcessors(Collection, ConfigurableListableBeanFactory) line: 663 FileSystemXmlApplicationContext(AbstractApplicationContext).invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory) line: 638 FileSystemXmlApplicationContext(AbstractApplicationContext).refresh() line: 407 FileSystemXmlApplicationContext.(String\[], boolean, ApplicationContext) line: 140 FileSystemXmlApplicationContext.(String) line: 84 Main.main(String\[]) line: 14 \[/code] 这是方法内部， 一清二楚啊。。 \[code="java"] /\** * Resolve the given key as JVM system property, and optionally also as * system environment variable if no matching system property has been found. * @param key the placeholder to resolve as system property key * @return the system property value, or `null` if not found * @see #setSearchSystemEnvironment * @see java.lang.System#getProperty(String) * @see java.lang.System#getenv(String) \*/ protected String resolveSystemProperty(String key) { try { String value = System.getProperty(key); if (value == null && this.searchSystemEnvironment) { value = System.getenv(key); } return value; } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Could not access system property '" + key + "': " + ex); } return null; } } \[/code]