> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iii.-using-spring-boot/16.-auto-configuration/16.2.-disabling-specific-auto-configuration-classes.md).

# 16.2. 禁用特定的自动配置类

如果发现启用了不想要的自动配置类，你可以使用`@EnableAutoConfiguration`注解的exclude属性禁用它们：

```java
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`属性exclude多个自动配置项（一个自动配置项集合）。

**注** 通过注解级别或exclude属性都可以定义排除项。
