springboot排除某些自動配置的操作方法
前言
Spring Boot 提供的自動配置非常強大,某些情況下,自動配置的功能可能不符合我們的需求,需要我們自定義配置,這個時候就需要排除/禁用Spring Boot 某些類的自動化配置了。比如:數(shù)據(jù)源、郵件,這些都是提供了自動配置的,我們需要排排除 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 {}
在配置文件中指定參數(shù)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
到此這篇關(guān)于springboot排除某些自動配置的文章就介紹到這了,更多相關(guān)springboot排除自動配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文帶你了解Java創(chuàng)建型設(shè)計模式之原型模式
原型模式其實就是從一個對象在創(chuàng)建另外一個可定制的對象,不需要知道任何創(chuàng)建的細節(jié)。本文就來通過示例為大家詳細聊聊原型模式,需要的可以參考一下2022-09-09Java Swing JRadioButton單選按鈕具體使用
這篇文章主要介紹了Java Swing JRadioButton單選按鈕具體使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12ZooKeeper入門教程二在單機和集群環(huán)境下的安裝搭建及使用
本文是ZooKeeper入門系列教程,涵蓋ZooKeeper的安裝使及單機集群環(huán)境搭建,通過實例和大量圖表,結(jié)合實戰(zhàn),幫助學習者理解和運用,有需要的朋友可以借鑒參考下2022-01-01