Java Apache CXF制作附加类“;“已知”;到JAXB上下文

Java Apache CXF制作附加类“;“已知”;到JAXB上下文,java,jaxb,cxf,jax-ws,Java,Jaxb,Cxf,Jax Ws,当JAXBContext将DTO序列化为XML时,如何配置ApacheCXF客户机和服务器以将其他类传递给JAXBContext 我不能使用@xmlseealAnnotations,因为这些类在jar的数据契约编译时是未知的,但在客户机编译时是已知的 在客户端,我尝试使用: Service service = Service.create(wsdlURL, serviceName, new UsesJAXBContextFeature(MyFactory.class)); T client =

当JAXBContext将DTO序列化为XML时,如何配置ApacheCXF客户机和服务器以将其他类传递给JAXBContext

我不能使用@xmlseealAnnotations,因为这些类在jar的数据契约编译时是未知的,但在客户机编译时是已知的

在客户端,我尝试使用:

Service service = Service.create(wsdlURL, serviceName, new UsesJAXBContextFeature(MyFactory.class));
T client = service.getPort(clazz);

但我遇到了一个异常,告诉我CXF不支持此功能

如果使用cxf.xml(spring xml)配置cxf,则可以使用以下内容:

<jaxws:endpoint/client>
  <jaxws:properties>
    <entry key="jaxb.additionalContextClasses">
      <array value-type="java.lang.Class">
          <value type="java.lang.Class">fullQualifiedClassName</value>
      </array>
    </entry>
   </jaxws:properties>
</jaxws:endpoint>


您也可以通过注释来完成

与弹簧靴CXF启动器配合使用

@Autowired
private Bus bus;

@Bean
public Endpoint createMyEndpoint() {

    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    Map<String, Object> properties = new HashMap<>();
    properties.put("jaxb.additionalContextClasses", getExtraClasses());
    factory.setProperties(properties);

    Endpoint endpoint = new EndpointImpl(bus, new MyWebService(),factory);
    endpoint.setProperties(new HashMap<>());
    endpoint.publish("/v1/service");
    return endpoint;
}

@SuppressWarnings("rawtypes")
private Class[] getExtraClasses() {
    List<Class> extraClassList = new ArrayList<>();

    extraClassList.add(A.class);
    extraClassList.add(B.class);

    return  extraClassList.toArray(new Class[extraClassList.size()]);
}
我是和你一起想出来的

@javax.jws.WebService
public class MyWebService implements MyPortType {
    //...
}