The bean definition XML syntax can instanciate virtually any class.
You can look at the Spring documentation for a complete reference here:
http://docs.spring.io/spring/docs/4.0.0.RELEASE/spring-framework-reference/htmlsingle/#beans-factory-class, out of which I extracted the following samples.
For example, you can instanciate any class with an empty constructor this way:
<bean id="exampleBean" class="examples.ExampleBean"/>
If the constructor is a static method, you can call it this way
<bean id="clientService"
class="examples.ClientService" factory-method="createInstance"/>
If you need to call a constructor with an argument, look at:
http://docs.spring.io/spring/docs/4.0.0.RELEASE/spring-framework-reference/htmlsingle/#beans-constructor-injection
<bean id="foo" class="x.y.Foo">
<constructor-arg ref="bar"/>
<constructor-arg ref="baz"/>
</bean>
Where bar
and baz
should be ids of other spring beans. If instead, you use the XML attribute value
, then you can use a primitive type directly.
For example :
<bean id="exampleBean" class="examples.ExampleBean">
<constructor-arg name="years" value="7500000"/>
<constructor-arg name="ultimateanswer" value="42"/>
</bean>
You can also opt for calling an empty constructor first and the call setters on your beans (or mix the two methods).
<bean id="exampleBean" class="examples.ExampleBean">
<!-- setter injection using the nested <ref/> element -->
<property name="beanOne"><ref bean="anotherExampleBean"/></property>
<!-- setter injection using the neater ref attribute -->
<property name="beanTwo" ref="yetAnotherBean"/>
<property name="integerProperty" value="1"/>
</bean>
There are very advanced configuration options, allowing you to override the way Spring interprets the XML to interpret ref/value attributes.
There is also a dedicated syntax for Maps, Lists, ...
An expression language called Spring-EL in that you can use for dynamic evaluation at runtime inside your XML.
Plus various pre/post processor options for more advanced scenarios (BeanFactoryAware, BeanFactoryPostProcessor, ...)
So, in your case, you could try to decompose like this :
<bean class="springtest.SomeBeanTest">
<constructor-arg index="0">
<bean class="java.nio.file.Paths" factory-method="get">
<constructor-arg index="0" value="your path" />
<!-- Edit: see @clay's edit to the question, the following is necessary too -->
<constructor-arg index="1"><list></list></constructor-arg>
</bean>
</constructor-arg>
</bean>
Note that when there is no ambiguity, the index attribute is not necessary.