Spring @DependsOn 和 @ConditionalOnBean 的区别

在 Spring 中,注解 @DependsOn@ConditionalOnBean 的区别如下:

1、都是当前bean实例化依赖另外的bean实例

2、@DependsOn 最终两个实例都会创建,它用来控制当前Bean 一定在 DependsOn 所指向的Bean后面实例化

3、@ConditionalOnBean 只有当所指向的Bean的实例存在时,才创建当前Bean,否则不创建。即要么都有,要么都无。


(END)

相关推荐
唐青枫1 天前
Java Spring WebFlux 实战指南:用 Mono、Flux 和 WebClient 写响应式接口
java·spring
咖啡八杯3 天前
GoF设计模式——策略模式
java·后端·spring·设计模式
Flittly4 天前
【AgentScope Java新手村系列】(11)中断与恢复
java·spring boot·spring
dunky4 天前
Spring 的三级缓存与循环依赖
后端·spring
码云数智-园园9 天前
C++20 Modules 模块详解
java·开发语言·spring
咖啡八杯9 天前
GoF设计模式——享元模式
java·spring·设计模式·享元模式
Flittly9 天前
【AgentScope Java新手村系列】(10)实战-多Agent天气助手
java·spring boot·spring
李少兄9 天前
从原理到实战:Spring IoC/DI 核心知识体系与高频面试题全解
java·后端·spring
shushangyun_9 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
ofoxcoding9 天前
在AI API聚合平台配置DeepSeek V3.2提示词缓存实战:快速接入与成本优化指南
人工智能·spring·缓存·ai