This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes How to autowire byName using interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to autowire byName using interface" Watch "How to autowire byName using interface" New topic

How to autowire byName using interface

Om Prakash Bijawat

Joined: Feb 01, 2013
Posts: 10
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 =""></bean>
<bean id = "strutsQuizMaster" class = ""></bean>
<bean id = "quizMasterService" class = "" 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?
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30070

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to autowire byName using interface
Similar Threads
method injection problem
Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExcep
autowiring byName in spring
Problem calling destroy method
Need help on Spring - Quartz Job deployment in Jboss server