SpringBoot中如何排除特定Bean的方法或实例?

2026-05-28 00:130阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计744个文字,预计阅读时间需要3分钟。

SpringBoot中如何排除特定Bean的方法或实例?

简介+说明+文本介绍SpringBoot如何排除特定的类(不将其扫描到容器中)。文本说明的这种情况下,是排除使用@Component等注解添加到容器中的类。如果想要排除自动配置(即:自定义starter),通“排除”。

简介

说明

本文介绍SpringBoot如何排除某个指定的类(不将它扫描到容器中)。

本文说的这种情况是排除本来使用@Component等加入容器的类。如果想要排除自动配置(即:自定义starter,通过spring.factories来指定的配置类),见此文:SpringBoot--排除自动配置类--方法/实例_IT利刃出鞘的博客-CSDN博客

需求

使用 RuoYi(若依)源码,不想用 RuoYi 自带的权限管理(ShiroConfig) ,但是不删除它,只是不让它生效。

方案1:@ComponentScan

@ComponentScan(excludeFilters =
{@ComponentScan.Filter(
type = FilterType.REGEX,
pattern = {com.ruoyi.framework.config.ShiroConfig"})})
@SpringBootConfiguration
public class RuoYiApplication {
...
}

1.在@ComponentScan 中指定 excludeFilters 属性。该属性指定排除的Bean/类。

阅读全文
标签:bean方法

本文共计744个文字,预计阅读时间需要3分钟。

SpringBoot中如何排除特定Bean的方法或实例?

简介+说明+文本介绍SpringBoot如何排除特定的类(不将其扫描到容器中)。文本说明的这种情况下,是排除使用@Component等注解添加到容器中的类。如果想要排除自动配置(即:自定义starter),通“排除”。

简介

说明

本文介绍SpringBoot如何排除某个指定的类(不将它扫描到容器中)。

本文说的这种情况是排除本来使用@Component等加入容器的类。如果想要排除自动配置(即:自定义starter,通过spring.factories来指定的配置类),见此文:SpringBoot--排除自动配置类--方法/实例_IT利刃出鞘的博客-CSDN博客

需求

使用 RuoYi(若依)源码,不想用 RuoYi 自带的权限管理(ShiroConfig) ,但是不删除它,只是不让它生效。

方案1:@ComponentScan

@ComponentScan(excludeFilters =
{@ComponentScan.Filter(
type = FilterType.REGEX,
pattern = {com.ruoyi.framework.config.ShiroConfig"})})
@SpringBootConfiguration
public class RuoYiApplication {
...
}

1.在@ComponentScan 中指定 excludeFilters 属性。该属性指定排除的Bean/类。

阅读全文
标签:bean方法