This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27206|Reply: 2

[Source] Spring Bean annotations on how to use Conditional

[Copy link]
Posted on 10/22/2021 12:21:44 PM | | |
After @Conditional annotation, many derivative annotations were launched based on this annotation, such as @ConditionalOnBean, @ConditionalOnMissingBean, @ConditionalOnExpression, @ConditionalOnClass...... Injecting beans dynamically has become more convenient. This article will explain @ConditionalOnBean annotations.

@ConditionalOnBeanWhen a given bean exists, the current bean is instantiated, which may not be registered to the IOC for some reason, in which case the current bean can be not registered as @ConditionalOnBean
@ConditionalOnMissingBeanWhen an interface has multiple implementation classes, if you only want it to have one implementation class, then add this annotation to each implementation class
@ConditionalOnClassWhen a given class name exists on the classpath, the current bean is instantiated
@ConditionalOnMissingClassWhen a given class name does not exist on the classpath, the current bean is instantiated

@ConditionalOnMissingBean Example

WebMvcConfig will not be loaded.





Previous:Mysql grouped sorting
Next:ESXI installed (CentOS system) virtual machine
Posted on 10/22/2021 2:08:06 PM |
Support learning
Posted on 10/23/2021 7:35:39 PM |
Learn to learn...
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com