我不明白为什么我不能在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)请注意,如果我自己注入服务器端口号,则在注入和启动应用程序时不会出现任何问题。
我在这个问题上转来转去,找不出我做错了什么。
发布于 2014-05-28 13:43:16
我不认为你可以使用@PropertySource向"application.properties“注入值--后者必须在读取任何@Configuration之前解析并准备好使用。你的外部属性可以放在"${user.dir}/application.properties“中,我认为这会实现你想要做的事情。
https://stackoverflow.com/questions/23899003
复制相似问题