IntelliJ IDEA shows errors when using Spring's @Autowired annotation

前端 未结 26 2239
栀梦
栀梦 2020-12-07 15:40

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

相关标签:
26条回答
  • 2020-12-07 15:45

    Remove .iml file from all your project module and next go to File -> Invalidate Caches/Restart

    0 讨论(0)
  • 2020-12-07 15:48

    I fixed it by adding the supress warning:

     @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
     @Autowired
     private ....
    
    0 讨论(0)
  • 2020-12-07 15:48

    You should check if you have @Component, @Repository or similar added on the class

    0 讨论(0)
  • 2020-12-07 15:49

    I had similar problem. I solved it by unchecking "Process explicitly annotated beans" option (see screenshot below). This option is enabled by default on linux. Now @Service and @Configurations annotations are visible. screenshot

    0 讨论(0)
  • 2020-12-07 15:49

    I might be a little late, but after spending hours and researching on this issue.

    I found out that in the latest version IntelliJ 2020 @AutoWired is optional and constructor based depedency injection is preferable.

    I sloved the problem by simply removing the @AutoWired Annotation from Service and Controller class and using constructor based dependency injection.

    This link might help.

    Happy Coding!

    0 讨论(0)
  • 2020-12-07 15:52

    I've solved this problem this way. In IntelliJ all of your packages should be in a sub package which is the sub package of main/java. For example I've put all of my packages under src/main/java/com.misisol.watchStore/ and spring could find my beans then after.

    0 讨论(0)
提交回复
热议问题