springboot ComponentScan multiple excludeFilters example
springbootTo use excludeFilters with @ComponentScan in Spring Boot, you can use the following example:
@ComponentScan(basePackages = "com.example",
excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.example.package1.*"),
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.example.package2.*")})
This will exclude any components in the package1 and package2 packages from being scanned and registered as beans in the application context.
You can also use the includeFilters attribute to specify which packages should be included in the scan, rather than specifying which packages should be excluded.
@ComponentScan(basePackages = "com.example",
includeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.example.package3.*"),
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.example.package4.*")})
This will only include components in the package3 and package4 packages in the scan, and all other packages will be excluded.
Other Article on Tag springboot
- - Can I compile and run a spring boot jar from inside another spring boot application
- - Response to preflight request doesnt pass access control check It does not have HTTP ok status.
- - springboot ComponentScan multiple excludeFilters example
- - springboot CORS policy
- - springboot No 'Access-Control-Allow-Origin' header is present on the requested resource