2

通常は JaxbMarshaller と CastorMarshaller という 2 つの異なるマーシャラーを使用する必要があります。多くの統合モジュールを備えた春のプロジェクトがあります。

<bean id="marshaller" class="org.springframework.oxm.castor.CastorMarshaller">
    <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>

これもエンドポイントに追加して JaxbMarshaller を指定しましたが、取得できません

public class MyEndPoint extends AbstractMarshallingPayloadEndpoint

JaxbMarshaller と CastorMarshaller の両方を使用する必要があります

4

2 に答える 2

2

最終的に、解決する必要がある 2 つの問題があります。

  1. JAXB と Castor マーシャラー/アンマーシャラーの両方を注入する
  2. いつ 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) を構成するための手順を示します。

于 2011-01-19T15:39:56.593 に答える
0

私はJAXBを省略し、Castorを使用するだけで行き止まりになりました。

于 2011-02-22T09:12:59.020 に答える