<xs:choice>利用CXF2.3生成javaBean

本文探讨了使用CXF2.3将WSDL文件转换为JavaBean时,元素类型生成的不同情况,特别关注了内部选择结构与外部元素之间的差异。
环境:
windows XP, jdk1.6, CXF2.3

test.wsdl文件:
<xs:complexType name="CalendarTime">
<xs:sequence>
<xs:choice>
<xs:element name="day" type="xs:unsignedInt"/>
<xs:element name="week" type="xs:unsignedInt"/>
</xs:choice>
<xs:element name="seconds" type="xs:unsignedInt"/>
</xs:sequence>
</xs:complexType>

利用CXF2.3的wsdl2java命令生成javaBean如下:
public class CalendarTime {
@XmlSchemaType(name = "unsignedInt")
protected Long day;
@XmlSchemaType(name = "unsignedInt")
protected week week;
@XmlSchemaType(name = "unsignedInt")
protected long seconds;
......
}

wsdl中day、week、seconds同样定义为type="xs:unsignedInt",生成的javaBean的类型却不同:
day---[color=red]Long[/color]
week--[color=red]Long[/color]
seconds--[color=blue]long[/color]

后来实验发现:<xs:choice>包含的类型都会生成基本类型封装类,而在<xs:choice>之外的则生成基本类型。

不知道这是为什么,有哪位高人指点一下?
在 Spring 与 Apache CXF 集成的配置文件中,`<cxf:bus>` 标签标红通常表示 XML 解析器无法识别该标签。这可能是由于缺少命名空间声明、依赖缺失或 IDE 缓存等原因导致。 以下是一个完整的、修复后的 `applicationContext.xml` 示例,确保 `<cxf:bus>` 能够被正确解析和使用: ```xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> <!-- 启用组件扫描 --> <context:component-scan base-package="com.example.soap"/> <!-- 定义服务实现类 Bean --> <bean id="helloWorld" class="com.example.soap.HelloWorldImpl"/> <!-- 配置 CXF Bus 并启用日志功能 --> <cxf:bus> <cxf:features> <cxf:logging/> </cxf:features> </cxf:bus> <!-- 发布 JAX-WS 服务端点 --> <bean id="helloWorldEndpoint" class="org.apache.cxf.jaxws.EndpointImpl"> <constructor-arg ref="bus"/> <constructor-arg ref="helloWorld"/> <property name="address" value="/HelloWorld"/> </bean> </beans> ``` ### 说明: - **命名空间声明**:必须包含 `xmlns:cxf="http://cxf.apache.org/core"` 和对应的 `xsi:schemaLocation` 指向 CXFXSD 文件路径,否则 `<cxf:bus>` 等标签将无法被识别[^1]。 - **CXF Bus 配置**:`<cxf:bus>` 是 CXF 的核心配置元素,用于定义消息处理链、日志记录、拦截器等功能。 - **依赖管理**:确保项目中已正确引入 CXF 的相关依赖,如 `cxf-core`、`cxf-rt-transports-http`、`cxf-rt-frontend-jaxws` 等 Maven 模块,以避免运行时类找不到的问题。 - **IDE 支持**:若标签仍然标红,尝试刷新项目依赖(如 Maven 的 `mvn clean install`)、重启 IDE 或清除缓存。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值