IntelliJ IDEA is showing errors when I use Spring\'s @Autowired
annotation in the class, but the class is functioning without any problem.
Here is this
a little late but i hope it helps to someone else.
Make sure to put the @Service on the implementation class for the service
@Service
public class ServiceNameImpl implements ServiceName {
@Override
public void method(ObjectType paramName) {
//CODE
}
}
That's how i fixed the error.
If you know that the bean exists and its just a problem of the inspections, then just add the following before the variable declaration:
@SuppressWarnings("SpringJavaAutowiringInspection")
@Inject MyClass myVariable;
Sometimes IntelliJ cannot resolve if a bean has been declared, for example when the bean is included conditionally and the condition resolution happens at runtime.
File -> ProjectStructure -> Modules -> +(in central column) -> Spring ->OK
I solved that adding a Web facet.
I had this problem with only one service with constructor based dependency injection with 2019.2.4 version of IntelliJ. I found it helpful to change the name of the service (shift + f6) and then discard the changes from the git level.
The following worked for me: