Search code examples
javaspringxml-configuration

Read system properties in Spring XML config application with expression language


It seems to be easy, but it does not work. I can't paste system property in my easy example:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:client.properties</value>
            </list>
        </property>
        <property name="searchSystemEnvironment" value="true"/>
        <property name="ignoreResourceNotFound" value="true"/>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    </bean>

    <bean id="client" class="com.epam.spring.Client"
          c:id="${id}"
          p:fullName="#{systemEnvironment['user.name']}"
          p:greeting="${greeting}"
    />

Bean Client is ok, but field fullName is always null. In every case i have in fullName NULL, help me, please, what's wrong? I tried to use other systemEnvironment['something.else'], but it does not help. Tries like this: p:fullName="#{ T(java.lang.System).getenv().get('java.version') }" But id don't want to work.


Solution

  • I found the solution! Issue in this line: p:fullName="#{systemEnvironment['user.name']}"

    Just write

    p:fullName="#{systemProperties['user.name']}

    and all is ok )))

    And it is important, I think, operational system: windows 10