Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-8986

Add the ability to Scan Packages for JAXB Marshalling (java example provided)


    • Last commented by a User:



      In our application we have a rapidly growing number of JAXB2 annotated classes. It is a right pain to add these classes manually to the "classesToBeBound" property in the Jaxb2Marshaller. Given that other components (I'm looking at you Hibernate : AnnotationSessionFactoryBean) have the ability to automatically add classes from packages that match annotations, why not then for the Jaxb2Marshaller (having to key in the classes manually is so old skool).

      I've extended Jaxb2Marshaller (file attached) that scans on the classpath for appropriately annotated classes. Please do review and I hope that this can be incorporated into the next release. I'm happy to make changes to the codebase if required to bring it up to Spring coding standards.

      It's a pity that afterPropertiesSet is marked as Final in Jaxb2Marshaller since I can't override that method to set up the setClassesToBeBound before then calling the super afterPropertiesSet. Currently as the code stands, I have to provide a dummy setClassesToBeBound and setLazyInit to be true. This dummy is then replaced by overriding the getJaxbContext. I think this needs rewriting.

      An example of use:

      <bean id="marshaller" class="foo.bar.AnnotationJaxb2Marshaller">
          <property name="lazyInit" value="true" />
          <property name="classesToBeBound">
          <property name="packagesToScan">



          Issue Links



              • Assignee:
                arjen.poutsma Arjen Poutsma
                dharrigan David Harrigan
                Last updater:
                Juergen Hoeller
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created:
                  Days since last comment:
                  6 years, 19 weeks ago