1

I have been started use Spring recently. And I didn't find the solution to my problem.

I have a component:

@Component
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Log4j2
public class CompX { ....

I would like to use it twice in a (component) class:

...
@Autowired
private CompX current;

@Autowired
private CompX old;
...

How can I do this? Always got following exception.

"org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type..."

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

This is because ambiguity and spring is confused which one to consider so please tell spring which one to use by qualifying like below :

@Autowired
@Qualifier("current")
private CompX current;

@Autowired
@Qualifier("old")
private CompX old;
Alien
  • 15,141
  • 6
  • 37
  • 57