I'm using Spring-ws with jaxb bindings. In my definition of the Spring Marshaller I declare the jaxb packages which this marshaller will marshall. Each of these is turned into a namespace definiton on the resulting xml doc.
<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.company.package1:com.company.package2:com.company.package3:com.company.package4">
</property>
</bean>
Results in
<ns1:request ns1="http://www.company.com/Package1" ns2="http://www.company.com/Package2" ns3="http://www.company.com/Package3" ns4="http://www.company.com/Package4">
<ns1:data>text
</ns1:data>
</request>
This was mildly irritating.
After a bit of searching I find its a 'performance feature' in Jaxb2
https://jaxb.dev.java.net/issues/show_bug.cgi?id=103
So they won't be fixing it.
The alternative from my point of view is to declare multiple marshallers, and use them where appropriate.
<bean id="jaxb2Marshaller1" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.company.package1">
</property>
</bean>
<bean id="jaxb2Marshaller2" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.company.package2">
</property>
</bean>
..etc..