java - How to inject Spring Bean for factory method requiring MyClass.class parameter -
i'm trying inject java.util.prefs.preferences bean in master controller. controller looks like:
@controller class mycontroller { @autowired private preferences preferences; }
the application-context.xml file creates bean java.util.prefs.preferences. uses factory method have following entry creating bean:
<bean id="preferences" class="java.util.prefs.preferences" factory-method="usernodeforpackage" />
preferences.usernodeforpackage(param) takes parameter class related preference. in case spring needs create bean performing call:
preferences.usernodeforpackage(mycontroller.class);
how can class passed in spring bean instantiated factory method? thanks
environment information:
java 7 spring 3.1
you can specify constructor-arg
element
<bean id="preferences" class="java.util.prefs.preferences" factory-method="usernodeforpackage"> <constructor-arg type="java.lang.class" value="com.path.mycontroller" /> </bean>
this explained in official documentation here, section 5.4.1.
arguments static factory method supplied via elements, same if constructor had been used. type of class being returned factory method not have of same type class contains static factory method, although in example is. instance (non-static) factory method used in identical fashion (aside use of factory-bean attribute instead of class attribute), details not discussed here.
Comments
Post a Comment