首页 > 解决方案 > Spring Boot - 如何在扫描期间排除一个组件?

问题描述

我有一个需要使用的 JAR 依赖项。该 JAR 中有一个组件干扰了我的 Spring Boot 应用程序的一部分。我需要排除那个 ONE 组件,并且目前无法更改 JAR 依赖项中的组件定义。

我尝试了以下方法,但它不起作用,bean 仍然加载:

@SpringBootApplication
@ComponentScan(useDefaultFilters = false, excludeFilters = [Filter(type = FilterType.ASSIGNABLE_TYPE, classes = [SomeBean::class])])

bean定义为:

@RestController
class SomeBean {

注意:这些片段在 Kotlin 中。

标签: springspring-bootkotlin

解决方案


尝试这个

@SpringBootApplication(exclude = { SomeBean.class })

推荐阅读