spring-boot-注解1

@Configration:声明该类是一个配置文件类,配合@Bean使用。

@Bean(name=‘’):用在@Configration配置类文件中,指定创建类的方法。方法中可以指定需要用注入的类当做参数。

@Component(user):定义一个类,让该类被扫描到,进入ioc容器

@Value(1):用在属性值上,指定初始化的方法或初始化值

@ComponentScan(“com.bjsxt.*”):用在@Configration的类上,定义扫描路劲.还可以有filter等属性,不多说

 

如果需要增加配置文件,添加依赖。

spring-boot-注解1

配置文件的内容:

spring-boot-注解1

使用springel注入

spring-boot-注解1

另一种方式注解读配置文件:

@ConfigrationProperties

spring-boot-注解1

 

当有多个配置文件时:默认会加载applicationContext.properties(yml),其他需要注解在主类备注声明:@PropertySource

spring-boot-注解1

@ImportResource 引入xml配置文件

spring-boot-注解1