【问题标题】:Placesholders in properties file doesn't substitute for environment variables属性文件中的占位符不能代替环境变量
【发布时间】:2017-05-17 09:03:11
【问题描述】:

我有一个带有占位符的 application.properties 文件的 Spring Boot 应用程序:

tommy.messagebroker.provider=activemq
tommy.messagebroker.tcpaddress=${JMS_HOST}
tommy.messagebroker.port=${JMS_PORT}

当我设置这些环境变量并运行应用程序时,它不会用这些占位符替换 env 变量的实际值...

这是我的主要应用程序类:

@SpringBootApplication
@ComponentScan(basePackages = {"com.tommy.server"})
public class tommyApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(AuditManagerApplication.class, args);
    }

}

在我的 pom.xml 中:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.3.RELEASE</version>
</parent>

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.5.3.RELEASE</version> 
 </dependency>

有人知道如何实现这种替代吗?

【问题讨论】:

  • 如何设置这些环境变量?
  • 在运行应用程序之前将它们添加到 Intellij“编辑配置”菜单中...
  • 请分享编辑配置截图

标签: spring spring-boot


【解决方案1】:

如果您在本地系统中设置这些环境变量,并且您使用的是 eclipse IDE。请关闭 Eclipse 并重新打开它,包括您的项目。由于某种原因,除非您关闭 ide 并重新打开它,否则 eclipse 不会获取环境变量。

【讨论】:

    猜你喜欢
    • 2015-11-26
    • 1970-01-01
    • 2013-09-07
    • 2011-07-13
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 2017-11-30
    相关资源
    最近更新 更多