Reputation: 578
Is it possible to inject Class param through constructor from xml file? How is it done? For example
public Server(Class<?>... configuration) {}
This is class with param to inject
This is my xml file
<constructor-arg index="0"></constructor-arg>
But what shall I do next?
Upvotes: 1
Views: 4044
Reputation: 3205
since args is an array of Object you can use :
<bean name="myBean" class="MyClass"> <constructor-arg> <list> <value>111</value> <value>222</value> <value>333</value> <value>444</value> </list> </constructor-arg> </bean>
Upvotes: -1
Reputation: 279970
If your parameter was of type Class<?>
, then all you would need is to provide the fully qualified class name
<constructor-arg index="0">java.lang.String</constructor-arg>
But since you have a varargs, you need to add an <array>
with values
<constructor-arg index="0">
<array>
<value>
java.lang.String
</value>
</array>
</constructor-arg>
Upvotes: 2