2

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.

1
  • Just a clarification: Please, note that in Java context "system properties" are set with -Dprop=value and are distinct from OS environment variables. Using SpEL and systemEnvironment accesses the latter, not "system properties" mentioned in the title. System properties are accessed by systemProperties, example in this answer: stackoverflow.com/a/22630883/658826 Commented Jul 12, 2021 at 8:22

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.