Java – specify a package for spring jaxb2marshaller instead of “classestobebound”

I tried to use jaxb2 Marshall and spring to organize a set of Java classes 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>

What I want to do is not to specify a list of classes, but to specify the package name containing all classes (COM. Example in the above example)

No one knows how to do this, or any other way, without me listing all the classes Any help will be appreciated!

thank you.

Solution

From spring 3.1 (I think) you can also use the packagestoscan attribute, which accepts wildcards It does not apply to elements without @ xmlrootelement annotation, just like the contextpath attribute These need to generate object factories

May look like:

<property name="packagesToScan">
    <list>
        <value>com.test.*</value>
        <value>com.*.test</value>
    </list>
</property>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>