javascript
《springboot系列十六》条件装配时configurationcondition和condition有什么区别?什么时候用configurationcondition? -凯发ag旗舰厅登录网址下载
针对条件装配我们讨论了如下内容:
在《springboot系列十三》:图文精讲@conditional条件装配实现原理一文中,我们知道了条件装配时是分两阶段(配置类解析、bean注册)进行的。
configurationcondition接口是spring4.0提供的注解,位于org.springframework.context.annotation包内,继承自condition接口;
public interface configurationcondition extends condition {/*** 返回当前condition可以被评估的配置阶段* return the {@link configurationphase} in which the condition should be evaluated.*/configurationphase getconfigurationphase();/*** condition应该被评估的各个配置阶段* the various configuration phases where the condition could be evaluated.*/enum configurationphase {/*** 配置类解析阶段* the {@link condition} should be evaluated as a {@code @configuration}* class is being parsed.*if the condition does not match at this point, the {@code @configuration}* class will not be added.*/parse_configuration,/*** bean注册阶段* the {@link condition} should be evaluated when adding a regular* (non {@code @configuration}) bean. the condition will not prevent* {@code @configuration} classes from being added.*
at the time that the condition is evaluated, all {@code @configuration}* classes will have been parsed.*/register_bean}}
configurationcondition中的getconfigurationphase()方法,用于返回configurationphase配置阶段(configurationphase 的枚举);
1、configurationcondition和condition的区别?
1> condition评估的时机:
2> 使用对比:
1)onbeancondition
1> onbeancondition类图:
2> onbeancondition实现的方法:
2)onclasscondition
1> onbeancondition类图:
2、什么时候用configurationcondition?
configurationphase的作用是控制条件评估(过滤)的时机:是在解析配置类的时候 还是在创建bean的时候。
一般而言configurationcondition多用于 只在注册bean阶段才进行条件评估的condition中使用,比如onbeancondition。以onbeancondition为例,其中的很多条件评估的依据只有在注册bean阶段才会相对更加完整。
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的《springboot系列十六》条件装配时configurationcondition和condition有什么区别?什么时候用configurationcondition?的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇:
- 下一篇: