<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=dharrigan" rel="nofollow">David Harrigan</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8986?redirect=false" rel="nofollow">SPR-8986</a></strong> and commented</p>
<p dir="auto">Hi,</p>
<p dir="auto">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 <strong>so</strong> old skool).</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">An example of use:</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;marshaller&quot; class=&quot;foo.bar.AnnotationJaxb2Marshaller&quot;&gt;
    &lt;property name=&quot;lazyInit&quot; value=&quot;true&quot; /&gt;
    &lt;property name=&quot;classesToBeBound&quot;&gt;
       &lt;list&gt;
           &lt;value&gt;foo.bar.Class&lt;/value&gt;
       &lt;/list&gt;
    &lt;/property&gt;
    &lt;property name=&quot;packagesToScan&quot;&gt;
        &lt;list&gt;
            &lt;value&gt;foo.bar.jaxb.model&lt;/value&gt;
        &lt;/list&gt;
    &lt;/property&gt;
&lt;/bean&gt;"><pre class="notranslate">&lt;<span class="pl-ent">bean</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>marshaller<span class="pl-pds">"</span></span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>foo.bar.AnnotationJaxb2Marshaller<span class="pl-pds">"</span></span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>lazyInit<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>true<span class="pl-pds">"</span></span> /&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>classesToBeBound<span class="pl-pds">"</span></span>&gt;
       &lt;<span class="pl-ent">list</span>&gt;
           &lt;<span class="pl-ent">value</span>&gt;foo.bar.Class&lt;/<span class="pl-ent">value</span>&gt;
       &lt;/<span class="pl-ent">list</span>&gt;
    &lt;/<span class="pl-ent">property</span>&gt;
    &lt;<span class="pl-ent">property</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>packagesToScan<span class="pl-pds">"</span></span>&gt;
        &lt;<span class="pl-ent">list</span>&gt;
            &lt;<span class="pl-ent">value</span>&gt;foo.bar.jaxb.model&lt;/<span class="pl-ent">value</span>&gt;
        &lt;/<span class="pl-ent">list</span>&gt;
    &lt;/<span class="pl-ent">property</span>&gt;
&lt;/<span class="pl-ent">bean</span>&gt;</pre></div>
<p dir="auto">-=david=-</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 GA</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/19255/AnnotationJaxb2Marshaller_v2.java" rel="nofollow">AnnotationJaxb2Marshaller_v2.java</a> (<em>5.10 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/19254/AnnotationJaxb2Marshaller.java" rel="nofollow">AnnotationJaxb2Marshaller.java</a> (<em>4.13 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398117760" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13835" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13835/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13835">#13835</a> HTTP response code 308 (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398117841" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13844" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13844/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13844">#13844</a> Add ClasspathScanningJaxb2Marshaller for spring OXM (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/8980ce712da209aa5cf742dd4bd58f09e5d46870/hovercard" href="https://github.com/spring-projects/spring-framework/commit/8980ce712da209aa5cf742dd4bd58f09e5d46870"><tt>8980ce7</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/79f32c7f33489bf9e746928d9e33fb29b53e0a96/hovercard" href="https://github.com/spring-projects/spring-framework/commit/79f32c7f33489bf9e746928d9e33fb29b53e0a96"><tt>79f32c7</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/ff9ad7adc603fd395c212b7329a2b0b2804a82bc/hovercard" href="https://github.com/spring-projects/spring-framework/commit/ff9ad7adc603fd395c212b7329a2b0b2804a82bc"><tt>ff9ad7a</tt></a></p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=loren%20rosen" rel="nofollow">Loren Rosen</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-305?redirect=false" rel="nofollow">SPR-305</a></strong> and commented</p>
<p dir="auto">The shell scripts in samples/jpetstore/db/hsqldb has DOS line delimiters instead of Unix delimiters. This can cause attempts to run this sample application to fail.</p>
<p dir="auto">What happens is that, when you start up the database via server.sh, the shell sees the end of the command as '-database jpetstore\c', where by \c I mean the carriage return character. Then when the sample code itself attempts to query the database, it gets an error since the database jpetstore (with no terminating carriage return) doesn't exist:</p>
<p dir="auto">org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [(mapped statement)] in task 'SqlMapTemplate'; nested exception is java.sql.SQLException: Table not found: CATEGORY in statement [select CATID, NAME, DESCN from CATEGORY where CATID = 'CATS']<br>
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:254)<br>
org.springframework.orm.ibatis.SqlMapTemplate.execute(SqlMapTemplate.java:116)<br>
org.springframework.orm.ibatis.SqlMapTemplate.executeQueryForObject(SqlMapTemplate.java:152)<br>
org.springframework.samples.jpetstore.dao.ibatis.SqlMapCategoryDao.getCategory(SqlMapCategoryDao.java:17)<br>
org.springframework.samples.jpetstore.domain.logic.PetStoreImpl.getCategory(PetStoreImpl.java:124)<br>
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
java.lang.reflect.Method.invoke(Method.java:324)<br>
org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:60)<br>
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:150)<br>
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:119)<br>
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)<br>
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)<br>
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)<br>
$Proxy0.getCategory(Unknown Source)<br>
org.springframework.samples.jpetstore.web.spring.ViewCategoryController.handleRequest(ViewCategoryController.java:31)<br>
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)<br>
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:495)<br>
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:321)<br>
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)</p>
<p dir="auto">To the beginning user it simply appears that the samples are broken. Some beginning users might even jump to the conclusion that spring itself doesn't work, since here even the sample code gets errors about bad SQL grammar. It took me most of a morning to figure out the problem.</p>
<p dir="auto">Presumably the problem occurs with the scripts in the petclinic sample as well, though I haven't tried them.</p>
<p dir="auto">Note also that it's possible some Unix shells could treat DOS line delimiters the same as Unix delimiters, and so not exhibit this bug. Here I'm using<br>
GNU bash, version 2.05b.0(1)-release (powerpc-apple-darwin7.0)</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.1 RC2</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398075607" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7861" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7861/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7861">#7861</a> DOS chars in sample app shell scripts (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>