【问题标题】:Spring jndi.xml placement holder using environment variable使用环境变量的 Spring jndi.xml 放置架
【发布时间】: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检查。

编辑:我发现我需要一些&lt;context:property-placeholder /&gt;,但不确定它是什么意思。 Exposing jndi variables as property place holder

【问题讨论】:

    标签: java spring tomcat


    【解决方案1】:

    经过一番研究,我发现在我的 context.xml 文件中添加 &lt;context:property-placeholder ignore-unresolvable="true"/&gt; 可以解决问题。来自Exposing jndi variables as property place holder

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 2018-07-31
      • 2019-08-03
      • 2015-07-07
      • 2021-11-09
      • 1970-01-01
      相关资源
      最近更新 更多