/ / Jaxb2MarshallerのpackagesToScanプロパティでJAXBElementを使用しているときにエンドポイント用のアダプターがありません-java、spring、exception、jaxb

Jaxb2MarshallerのpackagesToScanプロパティでJAXBElementを使用しているときにエンドポイント用のアダプタがありません - java、spring、exception、jaxb

私はJAXBElement <...>を使用している @XmlRootElement 指定されたXSDの生成されたクラスの注釈(これは変更できません)が、Springはまだjava.lang.IllegalStateException:No adapter for endpoint [...]を提供しています。マーシャラーは次のように定義されます。

<bean id="marsh" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<propety name="packagesToScan" value="com.foo.*.schemas" />
</bean>

ログでは、springがすべてのスキーマをロードしたことがわかります。起動時にendpointMapにトレースすると、そこに表示されますが、リクエストが来ると適切なアダプターがありません...

同じに直面している人?

回答:

回答№1は0

さて、私は今それを見ることができます contextPath プロパティが使用されていない場合、jaxb2marshallerインスタンスに設定されておらず(null)、次のプライベートメソッドが期待どおりに機能しません。

private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement) {
if (checkForXmlRootElement && AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) == null) {
return false;
}
if (StringUtils.hasLength(getContextPath())) {  // << -----
String packageName = ClassUtils.getPackageName(clazz);
String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":");
for (String contextPath : contextPaths) {
if (contextPath.equals(packageName)) {
return true;
}
}
return false;
}
else if (!ObjectUtils.isEmpty(getClassesToBeBound())) {
return Arrays.asList(getClassesToBeBound()).contains(clazz);
}
return false;
}

JAXBElement <>トリックはここでは動作しません:(