最終的に、解決する必要がある 2 つの問題があります。
- JAXB と Castor マーシャラー/アンマーシャラーの両方を注入する
- いつ JAXB または Castor を使用するかを決定する
項目 #1 - JAXB と Castor マーシャラー/アンマーシャラーの両方を注入する
org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapterには、marshaller プロパティと unmarshaller プロパティが 1 つだけあります。この問題を解決するには、次の 2 つの方法があります。
オプション 1 - サブクラス GenericMarshallingMethodEndpointAdapter
rg.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter をサブクラス化し、2 番目のマーシャラーに unmarshaller プロパティを導入できます。次に、これを次のように構成します。
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.example"/>
</bean>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation">
<value>classpath:config/service/mapping.xml</value>
</property>
</bean>
<bean
class="your.domain.YourGenericMarshallingMethodEndpointAdapter">
<property name="marshaller" ref="jaxbMarshaller" />
<property name="unmarshaller" ref="jaxbMarshaller" />
<property name="castorMarshaller" ref="castorMarshaller" />
<property name="castorMarshaller" ref="castorMarshaller" />
</bean>
オプション #2 - 独自のマーシャラーを実装する
JAXB と Castor の両方に対応する独自のマーシャラーを実装できます。次に、次のように構成します。
<bean id="marshaller" class="your.domain.CustomMarshaller">
<property name="contextPath" value="com.example"/>
<property name="mappingLocation">
<value>classpath:config/service/mapping.xml</value>
</property>
</bean>
<bean
class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
</bean>
項目 2 - いつ JAXB または Castor を使用するかを決定する
これは解決するのが難しい項目かもしれません。エンドポイントに JAXB と Castor の両方を認識させたら、マーシャリング操作を実行するためにいずれかを選択する必要があります。この側面は、上記のカスタム マーシャラー アプローチで解決する方が簡単かもしれません。
詳細については
Spring で JAXB を構成する手順は次のとおりです。
以下に、Castor (および JAXB) を構成するための手順を示します。