spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.59k stars 38.13k forks source link

Location value on PropertyPlaceholderConfigurer definition does not resolve placeholder if it is a system env [SPR-1893] #6586

Closed spring-projects-issues closed 12 years ago

spring-projects-issues commented 18 years ago

Akmal Sarhan opened SPR-1893 and commented

the following snippet does not work \ \\true\\ \\SYSTEM_PROPERTIES_MODE_FALLBACK\\

    <property name="locations">
        <list>
            <value>classpath:project-${SERVER_MODE}.properties</value>
            <value>classpath:messages.properties</value>
        </list>
    </property>
</bean> 

if SERVER_MODE is a system env. the solution is to change org.springframework.util.SystemPropertyUtils

to try to resolve the placeholder via: ... String propVal = System.getProperty(placeholder); if (propVal == null) propVal = System.getenv(placeholder); ...


Affects: 2.0 M3

Issue Links:

spring-projects-issues commented 18 years ago

Juergen Hoeller commented

This is actually not a bug but rather a lacking feature: PropertyPlaceholderConfigurer only resolves placeholders on bean definitions other than its own. If you specify a placeholder on a value within the PropertyPlaceholderConfigurer definition itself, you got a chicken-and-egg problem: The PropertyPlaceholderConfigurer cannot run because it cannot initialize itself.

What's really kicking in here to resolve such an "early" placeholder is Spring's SystemPropertyUtils class, which resolves them against system property values. What I've added there now is an automatic fallback to system environment variables, simply ignoring the placeholder if system environment access fails for it (which is the case on quite a few JVMs/platforms - system environment access is not encouraged on the Java platform).

Juergen

spring-projects-issues commented 18 years ago

Alex Wei commented

But not all property placeholders in the definition of a PropertyPlaceholderConfigurer can be resolved against system property values, such as "fileEncoding", which is quite painful for me as the the property file I load is on IBM mainframe using EBCDIC while my development is on Windows using ASCII.