Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to autowire byName using interface  RSS feed

 
Om Prakash Bijawat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

This is my interface:


These are my two implementation classes :


And this is my service class :


my Main method :



In my master-quiz.xml file I have written :

<bean id = "springQuizMaster" class ="com.services.SpringQuizMaster"></bean>
<bean id = "strutsQuizMaster" class = "com.services.StrutsQuizMaster"></bean>
<bean id = "quizMasterService" class = "com.services.QuizMasterService" init-method = "init" destroy-method = "destroy" autowire="byName">

When I use :

<constructor-arg ref="springQuizMaster"/> instead of autowire attribute it runs perfect

but while using autowiring it fails.
Can anyone help me out?
Thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37249
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't autowire here without more information because there are two beans that go with that constructor. Spring has no way to know which bean you want injected. That's why it works when you use the constructor.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!