. Advertisement .
..3..
. Advertisement .
..4..
I get an error
Could not autowire, no beans of ... type found
when trying to make basic unit test however IntelliJ is not correctly highlighting the test red. Marking the test as an error. How to fix the could not autowire no beans of type found error? Please give me some advice.
we had this same issue when creating a Spring Boot application using their As expected, the new annotation worked properly and our application ran smoothly but, Intellij kept complaining about unfulfilled For now, if the errors disturb you that much, then revert back to those three separate annotations. Otherwise, ignore Intellij…your dependency resolution is correctly configured, since your test passes. Always remember… Man is always greater than machine.@SpringBootApplication
annotation. This annotation represents @Configuration
, @EnableAutoConfiguration
and @ComponentScan
according to the spring reference.@Autowire
dependencies. As soon as we changed back to using @Configuration
, @EnableAutoConfiguration
and @ComponentScan
separately, the errors ceased. It seems Intellij 14.0.3 (and most likely, earlier versions too) is not yet configured to recognise the @SpringBootApplication
annotation.
Spring annotation
@Repository
should be added to the repository class.It should work without the annotation. IntelliJ won’t show any error if you add it.
Spring Data will conflict pagkages if it is used with the extending
Repository
classes. You must then indicate explicitly that you are pagking.Next, you can autowire your repository without any errors.
This is probably not the best solution. I guess you’re trying to register two repositoriums. However, it should work for you and not show any errors.
Maybe in the new version of IntelliJ can be fixed: https://youtrack.jetbrains.com/issue/IDEA-137023
If you have @Service annotation missing in your service class, it is worth checking.
@ComponentScan may sometimes need to know where components should be scanned. This can be done by passing the packages parameter to this annotation.
However, as already mentioned, @SpringBootApplication annotation replaces @ComponentScan, hence in such cases you must do the same:
At least in my case, Intellij stopped complaining.
I tried spring-boot 2.0 and intellij 2018.1.1 final edition, but I had the same problem.
I solved by placing @EnableAutoConfiguration in the main application class