我正在尝试使用@ComponentScan
注释的 IncludeFilters 属性管理我的 spring 应用程序加载的 bean。我使用类型的过滤器FilterType.REGEX
。我想匹配任何东西作为我模式的最后一部分,但我似乎根本没有那样工作。我有一个 bean 定义:
package org.example.child;
public class ChildDao {}
...
public class ChildService{}
...
public class ChildComponent{}
和配置类定义:
@ComponentScan(
value = "com.example",
includeFilters = {@ComponentScan.Filter(type = FilterType.REGEX,
pattern = "com.example.*.Child*")})
有了这样的配置,Spring 根本找不到任何 bean。
当星号不是用来匹配模式的最后一部分而是在两者之间的某个地方使用时,那么它似乎可以正常工作。
例如,以下配置匹配所有服务没有问题:
@ComponentScan(
value = "com.example",
includeFilters = {@ComponentScan.Filter(type = FilterType.REGEX,
pattern = "com.example.*.*Service")})
这是框架的设计行为还是应该可以使用这种“类似蚂蚁”的正则表达式模式来匹配模式的最后一部分?