Pass "HardCoded" Constructor Arg Class <T> to bean via Spring Config
I have a generic type that I injected into a service. Due to the way generic tools are implemented in Java, I need to have an arg constructor (or setterter) that contains information about the parameter class of a type type.
My question is: can I, by entering properties or specifying the arg constructor, pass an instance of the class with spring?
I know type T before runtime, so I know exactly what the Type parameter will be.
I thought it would look something like this:
<bean id="dataMartService" class="com.someclass">
<constructor-arg value="java.lang.class<com.someotherclass>" />
</bean>
Do I really not understand how this should happen?
+5
3 answers
You can use:
//for constructor
public CheckSpell(SpellCheker spellCheker){
this.spellCheker=spellCheker;
}
//Use object reference as bean
<bean id="textEditor" class="com.sring.spellCheck">
<constructor-arg ref="spellChecker"/>
</bean>
<bean id="spellCheker" class="com.spring.SpellCheker"/>
0
user2538100
source
share