16.2 Disabling specific auto-configuration

虽然自动配置是非侵入的,且会被你自身的配置覆盖(主要采用了条件注入的方式,见@EnableAutoConfiguration),你也可以在一开始就使用@EnableAutoConfiguration注解的exclude属性,将不是你所想要的自动化配置类(auto-configure classes)禁用掉

import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.context.annotation.*;

@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}

如果该类不在classpath中,你可以使用该注解的excludeName属性,并指定全限定名来达到相同效果。最后,你可以通过spring.autoconfigure.exclude属性(在属性文件application.properties中,多个值用逗号隔开)exclude多个自动配置项(一个自动配置项集合)。 excludeNameexclude都是传入一个数组

通过注解级别或属性文件中的exclude属性都可以定义排除项。

results matching ""

    No results matching ""