条件装配-Conditional
2025-4-20
| 2025-4-20
Words 203Read Time 1 min
type
status
date
slug
summary
tags
category
icon
password
全局搜索@Conditional,快捷键control+H,可以看到这个注解的继承树
由下图可以看出:在web项目情况下进行装配,在某个bean存在的条件下进行装配,不存在某个bean的情况下进行装配,在某个资源存在的情况下进行装配,等等。
notion image
测试ConditionalOnBean
ConditionalOnBean:容器中必须要有某个bean存在,才会在容器中加入这个bean
把tomcat这个bean从容器中移除
notion image
image-20220817100541468
校验容器中是否存在上面两个容器
notion image
image-20220817102126209
notion image
image-20220817102134877
在user01上使用@ConditionalOnBean,如果存在tomcat这个bean,再装配user01这个bean,那么此时,user01此时也就不存在了。
notion image
image-20220817102513156
notion image
image-20220817102523986
也可以加在类上,指定条件装配。
杨辉三角服务器安装java
Loading...
Catalog