Spring Boot 移除指定配置

Spring Boot About 648 words

移除 @Bean 标注的对象

@SpringBootApplicationexclude属性。

适用于@Configuration标注的类。

@SpringBootApplication(exclude = TestConfig.class)
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

移除指定组件

@ComponentScanexcludeFilters属性。

适用于@Component@Service@Controller@Repository等标注的组件。

@ComponentScan(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = TestComponent.class))
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

参考

https://www.baeldung.com/spring-componentscan-filter-type

Views: 1,598 · Posted: 2022-10-21

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh