Question

Spring Oxm allows you to use different marshallers/unmarshallers and Castor is one of them.

By default castor marshalles xml documents unindented and official documents tell that putting a castor.properties file in the search locations including the line org.exolab.castor.indent=true will override the default behavior.

Now, when using Spring Oxm in a web application (Spring Batch Admin) how can I override the castor.properties in the castor jar?

I have the following bean configurations (extra lines removed) and they do not have the necessary properties to set for this as far as I can see.

<bean id="myCastorMarshaller" 
    class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation" value="classpath:/mapping/my-mapping.xml" />
</bean>

<bean id="myXmlWriter" 
   class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="marshaller" ref="myCastorMarshaller" />
</bean>
Was it helpful?

Solution

Answering my own question: Using Spring 3.1.2 there is no solution for this question.

The class org.springframework.oxm.castor.CastorMarshaller should be in charge for setting properties and it has even jira issue for this SPR-8470 but the patches are not committed to main branch after more than a year.

Anyone may compare CastorMarshaller at Github with the proposed patch.

In brief, we need a setProperties(...) method in the CastorMarshaller but the patch is not committed.

OTHER TIPS

when using Spring Oxm in a web application (Spring Batch Admin) how can I override the castor.properties in the castor jar?

It is generally described in the link search locations you mentioned:

Castor loads the castor.properties in the following order:

  1. From classpath (usually from the jar file)
  2. From {java.home}/lib (if present)
  3. From the local working directory

Each properties file overrides the previous. So you don't have to come up with a properties file with all the properties and values, just the ones you want to change. This also means you don't have to touch the properties file found in the jar file.


Generally there are two kinds of properties file (with fixed file name) scanned and loaded by Castor, you can check out Castor source for more details:

We usually put castor.properties under the classpath root, which is your project's src/ directory (if you use maven, under src/main/java/).

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top