How to resolve error "The following classes could not be excluded because they are not auto-configuration classes"?

Viewed 14117

While starting Spring Boot Application I am getting this error:

The following classes could not be excluded because they are not auto-configuration classes:
        - org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration

This is how my application looks like. I have excluded WebsecurityConfiguration.class from EnablEAutoConfiguration but I keep on getting the above error. If I remove WebsecurityConfiguration.class from exclude my application is not able to get properties from application.yaml. Can you please help me in resolving this issue?

@Configuration
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class,
        ManagementWebSecurityAutoConfiguration.class, WebSecurityConfiguration.class

})
// @ComponentScan("com.infy.ceh.management")
@ComponentScan(basePackages = "com.infy.ceh.management", excludeFilters = @Filter(type = FilterType.CUSTOM, value = {
        ExcludeAnnotationFilter.class })

)
public class AgentApplication {

}
2 Answers

In the entry point for your SpringBoot app, use the following:

@SpringBootApplication
@ComponentScan(excludeFilters={@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE, value=<classThatYouWantToExclued>.class)})
public class TestApplication {

The error is telling you that WebSecurityConfiguration is not an auto-configuration class, but you are excluding it in the @EnableAutoConfiguration section. I would remove the class from EnableAutoConfiguration and filter it with @ComponentScan and ExcludeAnnotationFilter instead.

Related