【发布时间】:2021-05-19 14:11:53
【问题描述】:
我有一个带有占位符的 jndi.xml 文件的 tomcat 应用程序。此文件包含占位符${...},我希望将其从环境变量中替换。
jndi.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<bean id="widgetsRestBaseUrl" class="java.lang.String" factory-method="valueOf">
<constructor-arg value="${widgetsRestBaseUrl}"/>
</bean>
</beans>
pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.13.RELEASE</version>
</dependency>
据我了解,PropertySourcesPlaceholderConfigurer 在 bean 定义中解析 ${...},所以我希望它可以工作,但它没有。我错过了这里的任何东西吗?从春天开始,我确实在我的项目中看到了 PropertySourcesPlaceholderConfigurer 类。我也设置了环境变量,使用printenv检查。
编辑:我发现我需要一些<context:property-placeholder />,但不确定它是什么意思。
Exposing jndi variables as property place holder
【问题讨论】: