I want to inject prototype beans into a singleton factory. we're considering 4 options, and would like someone to emphasize the differences.
Sorted according to my personal preference:
- use
@lookup
method annotation (we use code based configuration). @Autowired
a Provider (one for each bean) andget()
for each type.- Provide static access to
ApplicationContext.getBean()
from anywhere in the application, andgetBean()
from there. - inject ApplicationContext, and
getBean()
.
I know getBean()
is a bad practice, but for some reason, I see many answers directing this way.
(whats the big difference between options 2 & 3 ?)