@PropertySource和@ImportResource

1.@PropertySource

@ConfigurationProperties是默认从全局配置文件中获取指定的值,比如

@ConfigurationProperties(prefix="person")这句话的意思是从application.yml或者application.properties中加载person的属性并映射到对应类的属性

那么如果我的person写在xxx.properties中,那么它就获取不到了

所以这个时候,我们便要加入注解@PropertySource(value={"classpath:xxx.properties"})//value里面的值是一个数组,可以多个值

2.@ImportResource:导入spring的配置文件,比如xxx.xml

比如我在bean.xml里面写了一个testService



    
    

那么我在application主函数加入注解@ImportResource(locations={"classpath:bean.xml"})

就能把testService加入spring容器中

 

你可能感兴趣的:(spring)