gpt4 book ai didi

java - 可以动态使用@XmlSeeAlso 吗?

转载 作者:行者123 更新时间:2023-11-30 11:48:31 27 4
gpt4 key购买 nike

而不是这个

@XmlSeeAlso({User.class,Role.class,Function.class})

我想要这样的东西:

@XmlSeeAlso(Access.getWebServiceClasses())

这可能吗?

我想要这个,因为我的 web 服务只包含接口(interface),如果我更改实现,我只想更改我的工厂,以便它返回正确的类,而不必更改 web 服务本身。

最佳答案

不可能的,因为注释元素必须是简单类型(字符串、基元或类(参见 annotations))。

但是(在 CXF 中)可以覆盖 org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.getExtraClass()默认检查 @XmlSeeAlso 的方法的界面。我的实现返回额外的 ObjectFactory类。

很可能您正在使用 <jaxws:endpoint />在 CXF 的 Spring XML 配置中。为了能够覆盖此方法,您创建了几个类:

  1. org.apache.cxf.jaxws.spring.EndpointDefinitionParser必须使用派生自 org.apache.cxf.jaxws.spring.EndpointDefinitionParser.SpringEndpointImpl 的类(使用 JAXWS 2.1 时)或来自 org.apache.cxf.jaxws22.spring.JAXWS22SpringEndpointImpl (JAXWS 2.2)
  2. 此类必须调用 super.setServiceFactory()路过org.apache.cxf.jaxws.support.JaxWsServerFactoryBean覆盖 getExtraClass()
  3. 您必须提供自己的 org.apache.cxf.jaxws.spring.NamespaceHandler (您可以创建派生类)为您自己的命名空间(例如 http://cxf.apache.org/jaxws/dynamic ),这将为 jaxws:endpoint 注册您自己的解析器元素:

    registerBeanDefinitionParser("端点", new EndpointDefinitionParser());

(抱歉,我无法提供完整示例 - 我是根据内存和 CXF 的源代码编写的)

关于java - 可以动态使用@XmlSeeAlso 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8759151/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com