Reputation: 183
I was trying out the following example in
and it works fine without any errors in Intellij IDEA. But as soon as I change the Spring Boot version from 2.4.4 to 2.7.1 in pom.xml, it throws an IDE error:
Could not autowire. No beans of 'HttpSecurity' type found for the following:
@Bean
public SecurityFilterChain configuration(HttpSecurity httpSecurity) throws Exception {
..........................
The application works fine but would be interested to know why this is happening. Version of IDE is IntelliJ IDEA 2022.1 (Ultimate Edition)
Upvotes: 11
Views: 25941
Reputation: 1343
Another reason of the issue except IDE problem is about versions of Spring Boot and Spring Security. Their versions should be compatible with each other.
If your spring boot project version is around 2.2.x
, you should use spring security 5.x
but If your spring boot project version is around 3.1.x
, you should use spring security 6.x
.
Reference: Error: Could not autowire. No beans of type 'httpSecurity' found
Author: M. Deinum
Upvotes: 0
Reputation: 6248
For some reason, the IDE cannot detect that the HttpSecurity
bean is configured by Spring Boot. You can get rid of the error by adding @EnableWebSecurity
to your configuration class, it solves it because the annotation imports the HttpSecurityConfiguration
configuration class.
The IntelliJ team has fixed this problem, you can get more information about the fix and which version it is available here.
Available in IntelliJ 2022.2 EAP 3, 2022.1.3
Upvotes: 29