Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDmitry Ponomarenko
18,175 Points"Couldn't autowire" inspection on UserService in IntelliJ IDEA
Greetings! For some reason IntelliJ shows an error here:
http://i.imgur.com/NfKCl3i.png
Tried to load completed project but still have the same problem. When I run app everything works fine, but that's still annoying. I used @SuppressWarnings("SpringJavaAutowiringInspection") to supress that warning from IDE, but I wonder why Chris doesn't have that error.
5 Answers
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsI think in our case with SecurityConfig
Intellijidea simply does not know where to look for bean UserService
.
Trying here and there, I also tried adding @ComponentScan('com.teamtreehouse')
on top of the SecurityConfig
class. It seems to work as well.
It is just we have to tell Intellijidea where to look for beans. Judging by StackOverflow posts, people know where and how to create proper application configuration files with settings where is which. I'm unfortunately not so good at this yet.
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsThe reason, Chris didn't get this error, because he is using Community Edition of IntellijIdea, whereas you probably are using Ultimate edition. Because only in Ultimate edition IntellijIdea is helping you with Spring Configuration. Chris used IntellijIdea Community Edition 2016.1.3 I think. I tried the same version - no error. Now I have ultimate version as well, and in it there is such error. If however you are using Community Edition, that error is strange...
Dmitry Ponomarenko
18,175 PointsThat makes sense, I still wonder why IntelliJ Ultimate shows this as an error though.
Dries Ketels
7,156 PointsI noticed that my UserServiceImpl wasn't annotated with @Service. Doing only that fixed my error. I did not have to annotate with @SuppressWarnings... or Componentscan either. Which makes sense to me because just annotating with @Service makes it being scanned on bootrun.
markmneimneh
14,132 PointsAdding this @ComponentScan("com.teamtreehouse.service") did not help in my case I am using Intellij 2016.2.2
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsI edited answer: try writing (I mistyped package name):
@ComponentScan("com.teamtreehouse")
Also keep in mind that @SuppressWarnings will also help:
@SuppressWarnings("SpringJavaAutowiringInspection")
Jeremiah Shore
31,168 PointsBe sure that you aren't missing the @Service
annotation on the UserServiceImpl
class.
George Michokostas
6,230 PointsI had to suppress the warning to make it work
@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
private UserService userService;