@PropertySource和@ImportSource

@PropertySource:加载指定的配置文件

  @PropertySource(value={"classpath:Person.properties"})

@ImportSource:导入Spring的配置文件,让Spring配置文件里面的内容生效

spring boot里面没有spring的配置文件,我们自己编写的配置文件,也不能自动识别,想让spring的配置文件生效,加载进来。用@ImportSource标注在一个配置类上

  @ImportSource(locations = {"classpath:bean.xml"})

Spring Boot推荐给容器中添加组件的方式

1、配置类---spring配置文件

2、使用@bean给容器添加组件

猜你喜欢

转载自www.cnblogs.com/gaofz/p/10385165.html