Monday 15 August 2011

java - autowire distinct beans in abstract class -



java - autowire distinct beans in abstract class -

i have next problem:

suppose have abstract class lets say:

public abstract class abstracthbmdao implements someinterface { @autowired protected sessionfactory sessionfactory; //getters & setters //interface stuff }

then several implementations of someinterface -> a_interface, b_interface, etc. ok if utilize same sessionfactory every implementation.

the problem want utilize distinct sessionfactory distinct grouping of of implementations , not want specify @qualifier. less flexible define these groups since need alter code. putting sessionfactory in abstract class if impossible specify @qualifier annotation.

is there way in xml bean definition ? tried declaring 2 sessionfactory beans , each of ref corresponding class, still homecoming nouniquebeandefinitionexception.

field injection fragile on own, , constructor injection should preferred whenever possible. that's clean solution here: create abstract (protected) constructor on base of operations class takes bean argument, , utilize @qualifier on subclass constructors.

java spring spring-annotations spring-bean

No comments:

Post a Comment