springboot排除某些自动配置

目录

前言

使用@SpringBootApplicationexclude时候

使用@EnableAutoConfiguration注解时

[在配置文件中指定参数spring.autoconfigure.exclude 进行排除](#在配置文件中指定参数spring.autoconfigure.exclude 进行排除)


前言

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
相关推荐
yunwei37几秒前
eBPF 入门实践教程:BPF Token,安全的委托式权限与程序加载
linux·后端·性能优化
136096757233 分钟前
旧 SQL 在新 PG 上能不能跑
后端
SamDeepThinking4 分钟前
配货单发货数为空告警误报治理:写表延迟复核方案
java·后端·架构
知守观5 分钟前
mirrorOf= 把私服请求拦去了公网镜像:本地能跑,CI 上内部包 404 排查
后端·ci/cd·maven
ly768911 分钟前
读懂 PostgreSQL 执行计划:从 EXPLAIN 输出定位 Spring Boot 慢 SQL 的代价估算偏差
spring boot·sql·postgresql·执行计划·explain analyze·慢sql优化
万物智能11 分钟前
鸿蒙UART总线怎么用?—【万物智能之开源鸿蒙OpenHarmony系统实战开发系列教程】
后端
\光辉岁月/11 分钟前
16.JavaSE-反射
java·反射
范什么特西15 分钟前
加深动态代理的理解
java
UrbanJazzerati16 分钟前
AutoHotkey v2 零基础快速入门 Part 5 游戏场景明暗阈值采集工具
后端
GoGeekBaird16 分钟前
我做了一个给 Agent 用的电商开源项目:开店、上架、改版,跟 Agent 说一声就行
后端·github·agent