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
eg1:
director:Settings - Editor - Inspections - Spring - Spring Core - Code - Autowiring for Bean Class
operate:checkout 勾去掉
eg2:
1.impl class add @service
like this:
@Service
public class CityServiceImpl implements CityService{
@Autowired
private CityDao cityDao;
like this
2.dao file class add @Repository
@Repository
public interface CityDao {
I had the same problem. I solved it by adding the Spring facet (File->Project Structure) for each relevant module, and then add the configuration files. For some projects (spring mvc), the config files where detected automatically. However, for a jar project, I had to add the configuration files manually.
Make sure you have your Spring bean definitions correct. Sometimes, the application works fine, it just displays an error in the IDE, check your project ‘iml’ file if you have a Spring facet defined.
I got the same problem. Mine was because the bean containing the autowired reference was not a Spring component (it was an EJB), but got a SpringBeanAutowiringInterceptor Interceptor allowing the use of autowiring. I think Intellij don't take this possibility in its Autowiring inspection.
Got the same error here!
It seems the Intellij cannot verify if the class implementation is a @Service or @Component.
Solve it just changing from Error to Warning(Pressing Alt + Enter).
Solved the issue by going to File >> Project Structure >> Facets and then adding all the configuration files to Spring Facet. After that it started detecting files in which the beans reside and was able to sort the issue. IntelliJ giving this check is quite valuable and IMHO shouldn't be disabled.