Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Autowired Issue

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day and thanks for viewing my post.

I have got an issue with @Autowired not working from a tutorial I found here: http://viralpatel.net/blogs/spring3-mvc-hibernate-maven-tutorial-eclipse-example/. I have used Autowired before in another application, but for some reason, I cannot figure out why the heck it is not working in this application. If I'm using component-scan, do I still need to create the bean? I did add the beans, but it still did not work. Here is what I have, can you see something I am not (see below)?

Thanks for your help!

 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<bean id="contactService" class="com.springhibernate.contact.service.ContactServiceImpl" />
<bean id="contactDAO" class="com.springhibernate.contact.dao.ContactDAOImpl" />


Problem is here, when you have made use of annotations, why are using above mappings in xml?

Please go through that explanations in that tutorial step by step and you will surely be able to wire service class into your controller which currently your code is deprived of.

Thanks,
Ashwini Kashyap | www.infocepts.com
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ashwini. I initially did not have those beans declared, but it didn't work. So, I added the beans and still it doesn't work. I did follow the tutorial and went through it several times trying to figure out why I keep getting the same ContactService error...no matter what I do. I spent two days trying to figure it out, so I'm out of ideas.
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.. But keep your xml without those mappings.
Also, why have you used @Configuration in controller class?

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The @Configuration was added in my attempt to correct the ContactService error; but it did not help. I have scoured the web looking for an answer and was hoping I would find the answer here.
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For those who come across the same issue, I was missing @Component in my ContactController class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic