Can anyone give me a hint how could I marshall a bean from a static XML file (main/resources/config.xml
) in Spring? I'd like to get Spring to do all the work for me, hopefully with some magic in the spring applicationContext.xml
file.
For example, I have the following:
@XmlRootElement(name="config")
public class MyConfig
{
private List<FooBar> foobars;
//constructor, getter + setter
}
@XmlType(name="fooBar")
public class FooBar
{
private String name;
private Foo foo;
private Bar bar;
//constructor, getters + setters
}
@XmlType(name="foo")
public class Foo
{
private String name;
//constructor, getters + setters
}
@XmlType(name="bar")
public class Bar
{
pr开发者_运维技巧ivate String name;
//constructor, getters + setters
}
And I want a bean loading with this XML;
<config>
<fooBar>
<name>foobar1</name>
<foo>
<name>foo1</name>
</foo>
<bar>
<name>bar1</name>
</bar>
</fooBar>
<fooBar>
<name>foobar2</name>
<foo>
<name>foo2</name>
</foo>
<bar>
<name>bar2</name>
</bar>
</fooBar>
</config>
I could just write a constructor and pass in the XML file as a resource, but I have the feeling that Spring has already solved the problem for me, I just can't find out how.
I believe that Spring does not include any non-spring configuration related xml processing. This may be the solution you want though: castor. This is not the only tool like this. It is; however, the only one that I can think of atm.
精彩评论