In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Today, I will talk to you about how to turn off the automatic configuration of Springboot, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
Springboot turns off automatic configuration
Springboot implements automatic configuration through @ EnableAutoConfiguration under @ SpringBootApplication, which saves developers a lot of time, but there may be some unnecessary configuration. What should I do if I want to turn off one of these configurations?
You can use the exclude parameter under @ SpringBootApplication.
Examples are as follows:
1. Turn off Redis automatic configuration @ SpringBootApplication (exclude= {RedisAutoConfiguration.class}) 2. SpringBoot automatically configures the database by default
If the business does not need it, you can also operate in the pringBootApplication annotations:
@ SpringBootApplication (exclude = {DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
Note: commas can be used to separate multiple configurations.
Turn on and off automatic task configuration process 1. Demand
You can dynamically control the scheduled tasks with @ Scheduled in springboot according to the switch configured by yourself.
two。 Solution
1. Delete @ EnableScheduling of the startup class
two。 Using condition to judge the condition
Public class SchedulerCondition implements Condition {@ Override public boolean matches (ConditionContext context, AnnotatedTypeMetadata metadata) {return Boolean.valueOf (context.getEnvironment () .getProperty ("com.myapp.config.scheduler.enabled")); / / is the yml value}}
3. Assemble new scheduled tasks to IOC
@ Configuration public class Scheduler {@ Conditional (SchedulerCondition.class) @ Bean (name = TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME) @ Role (BeanDefinition.ROLE_INFRASTRUCTURE) public ScheduledAnnotationBeanPostProcessor scheduledAnnotationProcessor () {return new ScheduledAnnotationBeanPostProcessor ();}} after reading the above, do you have any further understanding of how Springboot turns off automatic configuration? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.