您的位置:首页 > 编程语言 > Java开发

spring boot could not resolve placeholder in string value 问题解决方法

2017-09-28 16:03 1046 查看
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'hosts' in string value "${db.hosts}"
问题的产生是由于有多个properties文件造成的,如果再第一个properties文件中没有找,就不认为没有了,不继续找下一个properties文件解决办法如下:方法 一、在Application中加入一个静态方法import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;import org.springframework.core.io.ClassPathResource;@Configuration@SpringBootApplication@ComponentScanpublic class TestApplication {public final static void main(String[] args) {SpringApplication.run(VfcadaptorApplication.class, args);}@Bean    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {        PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();        c.setIgnoreUnresolvablePlaceholders(true);        return c;    }}方法二、 统一为属性name加前缀
<span lang="EN-US" font-size:11.5pt;font-family:consolas;"="">app.datasource.foo.type=daffaDataSource
app.datasource.foo.status =30
那就需要在类文件上加注解
@ConfigurationProperties("app.datasource.foo")@ConfigurationProperties("app.datasource.foo")Publicclass AA{PrivateString type;PrivateString status;...}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring
相关文章推荐