指定包而不是“classesToBeBound”对于春天Jaxb2Marshaller [英] Specify a package instead of "classesToBeBound" for spring Jaxb2Marshaller
问题描述
我正在尝试使用Jaxb2Marshaller来使用spring编组一组java类。我知道这可以使用以下代码完成
I am trying to use Jaxb2Marshaller to marshal a set of java classes using spring. I know this can be done using the following code
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.example.test1</value>
<value>com.example.test2</value>
</list>
</property>
</bean>
我想做的不是指定一个类列表,我想指定一下包含所有类的包名(在上面的例子中为com.example)。
What I would like to do is instead of specifying a list of classes, I would like to specify just the package name containing all the classes ( in the above case com.example).
有没有人知道这样做的方法,或任何其他不需要的方法我列出所有课程。任何帮助将不胜感激!
Does anyone know of a way to do this, or any other way which does not require me to list all the classes. any help would be appreciated !
谢谢。
推荐答案
来自Spring 3.1(我认为)你也可以使用 packagesToScan 属性,该属性接受通配符。它只适用于没有 @XmlRootElement
注释的元素,就像 contextPath 属性一样。这些需要生成对象工厂。
From Spring 3.1 (i think) you can use also the packagesToScan property, which accepts wildcards. It just doesn't work with elements without the @XmlRootElement
annotation, just like the contextPath property. These need generated object-factory.
看起来像:
<property name="packagesToScan">
<list>
<value>com.test.*</value>
<value>com.*.test</value>
</list>
</property>
这篇关于指定包而不是“classesToBeBound”对于春天Jaxb2Marshaller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!