<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=olivergierke" rel="nofollow">Oliver Drotbohm</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7931?redirect=false" rel="nofollow">SPR-7931</a></strong> and commented</p>
<p dir="auto">The <code class="notranslate">Jaxb2Marshaller</code> is only supporting classes annotated with <code class="notranslate">@XmlRootElement</code> currently and there's no way to override that behaviour as <code class="notranslate">supportsInternal(Class, boolean)</code> is private. There are cases when you want to (un)marshal classes that are <code class="notranslate">@XmlType</code> annotated only. Especially when working with XJC, you get the <code class="notranslate">@XmlRootElement</code> annotation only for classes that have their <code class="notranslate">xsd:simpleType</code> or <code class="notranslate">xsd:complexType</code> nested inside the <code class="notranslate">xsd:element</code> declaration (see <a href="http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html" rel="nofollow">this blog entry</a> for why that's the case). However, if you have a type that can be reused <strong>and</strong> used as a root element's type, XJC will not create the <code class="notranslate">@XmlRootElement</code> annotation but rather a factory method inside the <code class="notranslate">ObjectFactory</code> class. To get those classes (un)marshalled, you currently have to copy large parts of <code class="notranslate">Jaxb2Marshaller</code> as there's no way to disable the check for the annotation. So it would be cool if this was configurable through a bean property or at least changeable so that a subclass could potentially call <code class="notranslate">supportsInternal(clazz, false)</code>.</p>
<hr>
<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="398152851" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14376" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14376/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14376">#14376</a> Jaxb2Marshaller should support JaxbElement (<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/01d2082090fa59dfadff6bf092f99a4cd37f82f6/hovercard" href="https://github.com/spring-projects/spring-framework/commit/01d2082090fa59dfadff6bf092f99a4cd37f82f6"><tt>01d2082</tt></a></p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=david_syer" rel="nofollow">Dave Syer</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8077?redirect=false" rel="nofollow">SPR-8077</a></strong> and commented</p>
<p dir="auto">There is currently no "standard" way to do this, so users have to write their own and there are literally thousands of implementations out there with very common features.  CommandLineJobRunner from Spring Batch has some useful ideas in it, but it also has batch-specific options.  Ideally I'd like to simply extend or configure a standard component that does the context loading and autowiring piece, maybe collects some arguments from stdin, etc.  Maybe in the name of DRY, it would be useful to pick out some useful features and implement something now we have a new major point release in progress.</p>
<p dir="auto">Suggested features:</p>
<ul dir="auto">
<li>An API for command line options (probably duplicating commons-cli here, so maybe depend on that, or maybe just allow override for options gathering so users can plugin external library if needed?)</li>
<li>Accept arguments on command line and optionally append from stdin.</li>
<li>Standard (e.g. first) argument for locating a Spring configuration (XML, package or class name - I recommend sticking to a single config file and import from there if there are more, or else the argument could accept wildcards).</li>
<li>Autowiring of fields in the runner instance, so extensions can add <code class="notranslate">@Autowired</code> fields and have them supplied magically.</li>
<li>Clear semantics and documentation about how to shutdown the application and ensure the application context is closed (depends on whether there are any non-daemon threads), and allow shutdown when main() ends or on CTRL-C according to taste.</li>
<li>Optional call to System.exit() with status determined through e.g. a protected method</li>
<li>A way to initialize the Environment by plugging in a context initializer a la web.xml</li>
<li>Optional bootstrap properties in a file or Resource, or some other way to initialize the Environment without writing code</li>
</ul>
<hr>
<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="398116777" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13684" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13684/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13684">#13684</a> Support simplified main class application context / dependency management</li>
</ul>
<p dir="auto">5 votes, 6 watchers</p>