diff --git a/spring/Spring core/Spring Core IOC.md b/spring/Spring core/Spring Core IOC.md index 2dca33d..b12b852 100644 --- a/spring/Spring core/Spring Core IOC.md +++ b/spring/Spring core/Spring Core IOC.md @@ -177,4 +177,7 @@ ``` - 作为一种回退机制,当bean的qualifier未被定义时,bean的name属性将会被作为其qualifier,autowired时会根据@Qualifier注解中指定的值匹配具有相同name的bean对象 - 若想根据bean的name进行匹配,无需@Qualifier注解,只需要将注入点的name(filed的变量名,标注为@Autowired函数的形参名)和bean的name进行比较,如果相同则匹配成功,否则匹配失败 - - @Autowired同样支持自身引用的注入,但是自身引用的注入只能作为一种fallback机制。如果当前IOC容器中存在其他的同类型对象,那么其他对象会被优先注入,对象自己并不会参与候选的对象注入。但是,如果IOC中并不存在其他同类型对象,那么自身对象将会被作为引用注入。 \ No newline at end of file + - @Autowired同样支持自身引用的注入,但是自身引用的注入只能作为一种fallback机制。如果当前IOC容器中存在其他的同类型对象,那么其他对象会被优先注入,对象自己并不会参与候选的对象注入。但是,如果IOC中并不存在其他同类型对象,那么自身对象将会被作为引用注入。 + - @Resource + - @Resource标签类似于@Autowired标签,但是@Resource具有一个name属性用来匹配bean对象的name属性 + - @Resource标签首先会对具有相同name的bean对象,如果没有匹配到具有相同name的bean对象,才会fallback到类型匹配 \ No newline at end of file diff --git a/spring/spring boot/spring core feature.md b/spring/spring boot/spring core feature.md index a60e820..ca1eb4f 100644 --- a/spring/spring boot/spring core feature.md +++ b/spring/spring boot/spring core feature.md @@ -86,6 +86,24 @@ private String relationship; } ``` + * @ConfigruationProperties添加绑定后为绑定了环境变量的类注册bean对象到容器内中的方法 + * 通过@ConfigurationPropertiesScan注解来定义扫描路径 + * 通过@EnableConfigurationProperties来显式制定注册bean对象的属性类 + ```java + // 指定想要注册的属性类 + @Configruation + @EnableConfigurationProperties({PropertyBean1.class,...}) + class ConfigurationRegisterBean { + // ... + } + + // 通过@ConfigurationPropertiesScan来自动扫描 + @SpringBootApplication + @ConfigurationPropertiesScan({"package-path-1",...}) + class SpringBootApplicationDemo { + // ... + } + ``` * 如果为@ConfigurationProperties指定@ConstructorBinding注解,可以指定构造器绑定 * 如果为一个类指定了构造器绑定,那么该类中的嵌套成员(对象域)也会通过构造器绑定 * 可以通过@DefaultValue来为配置文件中没有指定的域指定默认值 @@ -103,11 +121,16 @@ my.map.[key1]=value1 my.map.[key2]=value2 ``` + * 向properties中添加list类型的值,同样可以用[]来包围index + ```properties + my.list[0]=value0 + my.list[1]=value1 + ``` * Duration绑定 * 默认情况下,不指定时间单位时单位是ms * 通过@DurationUnit指定时间单位 * DataSize绑定 - * 默认情况下,DataSize的单位是byte + * 默认情况下,DataSize的单位是byte * 可以通过@DataSizeUnit来显示指定单位 * @Value和@ConfigurationProperties区别: * @Value只有当其value值是"first-second"形式时,才支持relaxed binding