springboot排除某些自動(dòng)配置的操作方法
前言
Spring Boot 提供的自動(dòng)配置非常強(qiáng)大,某些情況下,自動(dòng)配置的功能可能不符合我們的需求,需要我們自定義配置,這個(gè)時(shí)候就需要排除/禁用Spring Boot 某些類的自動(dòng)化配置了。比如:數(shù)據(jù)源、郵件,這些都是提供了自動(dòng)配置的,我們需要排排除 Spring Boot 的自動(dòng)化配置交給我們自己來自定義,該如何做呢?
使用@SpringBootApplicationexclude時(shí)候
使用注解的時(shí)候,使用@SpringBootApplicationexclude 屬性進(jìn)行排除指定的類
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) //@EnableApolloConfig public class HighApplication {}
當(dāng)自動(dòng)配置類不在類路徑下的時(shí)候,使用excludeName 屬性進(jìn)行排除指定的類名全路徑
@SpringBootApplication(excludeName = "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class") //@EnableApolloConfig public class HighApplication {}
使用@EnableAutoConfiguration注解時(shí)
單獨(dú)使用注解的@EnableAutoConfigurashiw時(shí)候:
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class) //@EnableApolloConfig public class HighApplication {}
當(dāng)自動(dòng)配置類不在類路徑下的時(shí)候,使用excludeName 屬性進(jìn)行排除指定的類名全路徑:
@EnableAutoConfiguration(excludeName = "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class") //@EnableApolloConfig public class HighApplication {}
在配置文件中指定參數(shù)spring.autoconfigure.exclude 進(jìn)行排除
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
到此這篇關(guān)于springboot排除某些自動(dòng)配置的文章就介紹到這了,更多相關(guān)springboot排除自動(dòng)配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文帶你了解Java創(chuàng)建型設(shè)計(jì)模式之原型模式
原型模式其實(shí)就是從一個(gè)對(duì)象在創(chuàng)建另外一個(gè)可定制的對(duì)象,不需要知道任何創(chuàng)建的細(xì)節(jié)。本文就來通過示例為大家詳細(xì)聊聊原型模式,需要的可以參考一下2022-09-09Java Swing JRadioButton單選按鈕具體使用
這篇文章主要介紹了Java Swing JRadioButton單選按鈕具體使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12java基于TCP協(xié)議實(shí)現(xiàn)聊天程序
這篇文章主要為大家詳細(xì)介紹了java基于TCP協(xié)議實(shí)現(xiàn)聊天程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07ZooKeeper入門教程二在單機(jī)和集群環(huán)境下的安裝搭建及使用
本文是ZooKeeper入門系列教程,涵蓋ZooKeeper的安裝使及單機(jī)集群環(huán)境搭建,通過實(shí)例和大量圖表,結(jié)合實(shí)戰(zhàn),幫助學(xué)習(xí)者理解和運(yùn)用,有需要的朋友可以借鑒參考下2022-01-01