Spring 启动@ComponentScan。如何从扫描中排除除一个子包或 class 之外的所有包?
Spring boot @ComponentScan. How to exclude all packages from scan except one subpackage or class?
@ComponentScan(
excludeFilters = {
@ComponentScan.Filter(
type = FilterType.REGEX,
pattern =
"com.base.package.*"
)
)
在 com.base.package 之下。有一个class不想被排除,我怎么能把这个class包含进去?
密钥在正则表达式中。假设您要排除除名为 MyClass
之外的所有 类。您可以使用否定先行将其从正则表达式匹配中排除。请尝试以下操作。
@ComponentScan(
excludeFilters = {
@ComponentScan.Filter(
type = FilterType.REGEX,
pattern =
"(?!.*MyClass)com\.base\.package\..*"
)
)
@ComponentScan(
excludeFilters = {
@ComponentScan.Filter(
type = FilterType.REGEX,
pattern =
"com.base.package.*"
)
)
在 com.base.package 之下。有一个class不想被排除,我怎么能把这个class包含进去?
密钥在正则表达式中。假设您要排除除名为 MyClass
之外的所有 类。您可以使用否定先行将其从正则表达式匹配中排除。请尝试以下操作。
@ComponentScan(
excludeFilters = {
@ComponentScan.Filter(
type = FilterType.REGEX,
pattern =
"(?!.*MyClass)com\.base\.package\..*"
)
)