【发布时间】:2014-07-16 22:22:03
【问题描述】:
我无法弄清楚为什么我无法在 spring-boot 中将值注入到我的 application.properties 文件中。外部属性到 logging.file 变量中。我有一个如下所示的 application.properties 文件
logging.file=${mylogfile}
server.port=${myport}
对应的Spring-boot应用类
@PropertySources({
@PropertySource("file:///c:/myfolder/externalprops.properties"),
})
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
和外部属性文件
mylogfile=myoutput.log
myport=8060
当我运行 spring-boot 1.0.2.REL 应用程序时,每次尝试将 mylogfile 注入 application.properties 中的 logging.file 属性时,都会收到以下异常
Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'mylogfile' in string value "${mylogfile}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
请注意,如果我自己注入服务器端口号,我在注入和启动应用程序时不会遇到任何问题。
我在这个问题上兜圈子,无法弄清楚我做错了什么。
【问题讨论】:
标签: properties configuration spring-boot