File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
author & internet detective

Joined: May 26, 2003
Posts: 33130

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: How to autowire byName using interface
It's not a secret anymore!