Friday, 15 May 2015

java - Retrieving beans that are scope prototype using getBean -



java - Retrieving beans that are scope prototype using getBean -

i have read here using considered applicationcontext.getbean("somebeananmehere") bad.

if so, how programmatically beans (depends on user on kind of bean wants, let's can take different grocery items eg apple,soap,detergent)?

let's

switch(num){ case 1 : mygrocery = (groceryitem) applicationcontext.getbean("soap");break; case 2: mygrocery = (groceryitem) applicationcontext.getbean("apple");break; default: //more code here }

this doing in application user selecting or grocery items. (this console application)

if applicationcontext.getbean considered bad, alternative ?

you looking lookup method injection.

see http://static.springsource.org/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-method-injection

java spring dependency-injection inversion-of-control

No comments:

Post a Comment