目錄
前言
使用@SpringBootApplicationexclude時候
使用@EnableAutoConfiguration注解時
?在配置文件中指定參數(shù)spring.autoconfigure.exclude 進行排除
前言
Spring Boot 提供的自動配置非常強大,某些情況下,自動配置的功能可能不符合我們的需求,需要我們自定義配置,這個時候就需要排除/禁用Spring Boot 某些類的自動化配置了。比如:數(shù)據源、郵件,這些都是提供了自動配置的,我們需要排排除 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 屬性進行排除指定的類名全路徑:文章來源:http://www.zghlxwxcb.cn/news/detail-646731.html
@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的寫法:文章來源地址http://www.zghlxwxcb.cn/news/detail-646731.html
spring:
autoconfigure:
exclude:
- cn.hutool.extra.spring.SpringUtil
- com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration
到了這里,關于springboot排除某些自動配置的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!