-
May 27th, 2010, 01:54 PM
#1
@Autowired dependency injection
I have a file TradeIdeaServiceImpl.java where I have
@Autowired
protected TradeIdeaDAO tradeIdeaDAO;
and then I have a method createIdea() where there is
tradeIdeaDAO.closeIdea()
Now I have one more file Save2Database.java where I have
@Autowired
protected TradeIdeaService tradeIdeaService;
and then there is a method
tradeIdeaService.closeIdea(),
Now, I am trying to implement bean configuration for this @autowiring, I have appConfig.xml
<context:annotation-config />
<bean id="tradeIdeaDAO" class="clink.tide.service.idea.TradeIdeaDAOImpl"/>
<bean id="tradeIdeaService" class="clink.tide.service.idea.TradeIdeaServiceImp l"/>
when i try to run its giving me error
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'tradeIdeaService': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: protected clink.tide.service.idea.TradeIdeaDAO clink.tide.service.idea.TradeIdeaServiceImpl.trade IdeaDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [clink.tide.service.idea.TradeIdeaDAO] is defined: expected single matching bean but found 2: [tradeIdeaDAO, tradeIdeaDAOImpl]
Can somebody help me out in configuring the beans properly.
-
May 28th, 2010, 02:34 AM
#2
@Autowire injects the beans based on the type, if more than one bean of the same type found, it throws this exception.
use @Resource to inject based on the bean name, if you really want to have more than one instance of the same bean type
-
May 30th, 2010, 08:46 PM
#3
Hi bijayab02,
In order to force autowire work as wiring byName you can use the following:
@Autowired
@Qualifier("tradeIdeaDAO")
protected TradeIdeaDAO tradeIdeaDAO;
I hope that this solve your problem.
Regards
Last edited by gmateo; May 30th, 2010 at 08:47 PM.
Reason: wrong word
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules