情景:因为不可能所有的属性都放在全局文件中,所以需要把一些跟springboot无关的东西放在其他文件,用 @PropertySource:加载指定的配置文件;
所以我在javabean中直接用了此注解
@PropertySource(value = {"classpath:"})
@Component public class FoundBean {
xxx
}
在springboot单元测试中,发现并没有读取到内容,后来发现此注解只是加载进全局文件,所以还需要另一个注解(@ConfigurationProperties(prefix = “person”))读取内容
@ConfigurationProperties(prefix = "FoundBean")
@PropertySource(value = {"classpath:"})
@Component
public class FoundBean {
xxx
}
测试成功