springboot排除某些自动配置的操作方法
前言
Spring Boot 提供的自动配置非常强大,某些情况下,自动配置的功能可能不符合我们的需求,需要我们自定义配置,这个时候就需要排除/禁用Spring Boot 某些类的自动化配置了。比如:数据源、邮件,这些都是提供了自动配置的,我们需要排排除 Spring Boot 的自动化配置交给我们自己来自定义,该如何做呢?
使用@SpringBootApplicationexclude时候
使用注解的时候,使用@SpringBootApplicationexclude 属性进行排除指定的类
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
//@EnableApolloConfig
public class HighApplication {}当自动配置类不在类路径下的时候,使用excludeName 属性进行排除指定的类名全路径
@SpringBootApplication(excludeName = "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class")
//@EnableApolloConfig
public class HighApplication {}使用@EnableAutoConfiguration注解时
单独使用注解的@EnableAutoConfigurashiw时候:
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
//@EnableApolloConfig
public class HighApplication {}当自动配置类不在类路径下的时候,使用excludeName 属性进行排除指定的类名全路径:
@EnableAutoConfiguration(excludeName = "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class")
//@EnableApolloConfig
public class HighApplication {}在配置文件中指定参数spring.autoconfigure.exclude 进行排除
spring.autoconfigure.exclude=cn.hutool.extra.spring.SpringUtil,com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration #==================================================================================== 或者 #==================================================================================== spring.autoconfigure.exclude[0]=com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration spring.autoconfigure.exclude[1]=cn.hutool.extra.spring.SpringUtil
yml的写法:
spring:
autoconfigure:
exclude:
- cn.hutool.extra.spring.SpringUtil
- com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration到此这篇关于springboot排除某些自动配置的文章就介绍到这了,更多相关springboot排除自动配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
详解SpringBoot的三种缓存技术(Spring Cache、Layering Cache 框架、Alibaba J
这篇文章主要介绍了SpringBoot的三种缓存技术,帮助大家更好的理解和学习springboot框架,感兴趣的朋友可以了解下2020-10-10
Spring Boot 日志配置详解:log4j2.xml 的完整配置指南
本文介绍了在SpringBoot项目中配置Log4j2的方法,包括选择Log4j2的原因、Maven依赖配置、application.yml配置、log4j2.xml完整配置详解,以及性能优化建议,通过合理配置,可以构建高性能的异步日志记录系统,满足日常开发和运维需求2026-04-04
springboot 自定义异常并捕获异常返给前端的实现代码
在开发中,如果用try catch的方式,每个方法都需要单独实现,为了方便分类异常,返回给前端,采用了@ControllerAdvice注解和继承了RuntimeException的方式来实现,具体实现内容跟随小编一起看看吧2021-11-11


最新评论