【问题标题】:Read system properties in Spring XML config application with expression language使用表达式语言读取 Spring XML 配置应用程序中的系统属性
【发布时间】:2018-04-03 07:19:19
【问题描述】:

这似乎很容易,但它不起作用。 我无法在我的简单示例中粘贴系统属性:

<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 没问题,但字段 fullName 始终为空。 在每种情况下,我的全名都是 NULL,请帮帮我,怎么了? 我尝试使用其他 systemEnvironment['something.else'],但没有帮助。 像这样尝试: p:fullName="#{ T(java.lang.System).getenv().get('java.version') }" 但是我不想工作。

【问题讨论】:

  • 澄清一下:请注意,在 Java 上下文中,“系统属性”设置为 -Dprop=value,并且与操作系统环境变量不同。使用 SpEL 和 systemEnvironment 访问后者,而不是标题中提到的“系统属性”。系统属性由systemProperties 访问,例如在这个答案中:stackoverflow.com/a/22630883/658826

标签: java spring xml-configuration


【解决方案1】:

我找到了解决方案!此行中的问题: p:fullName="#{systemEnvironment['user.name']}"

随便写

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

一切正常)))

我认为重要的是操作系统:Windows 10

【讨论】:

    猜你喜欢
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 2020-12-15
    • 1970-01-01
    相关资源
    最近更新 更多