16.5. 使用 Spring 配置 CXF 端点
您可以使用以下的 Spring 配置文件配置 CXF 端点,也可以将端点嵌入到 camelContext 标签中。当您调用服务端点时,您可以将 operationName 和 operationNamespace 标头设置为明确声明您要调用的操作。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort"
serviceClass="org.apache.hello_world_soap_http.GreeterImpl"/>
<cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort"
wsdlURL="testutils/hello_world.wsdl"
serviceClass="org.apache.hello_world_soap_http.Greeter"
endpointName="s:SoapPort"
serviceName="s:SOAPService"
xmlns:s="http://apache.org/hello_world_soap_http" />
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:routerEndpoint" />
<to uri="cxf:bean:serviceEndpoint" />
</route>
</camelContext>
</beans>
务必包含 root beans 元素上指定的 JAX-WS schemaLocation 属性。这允许 CXF 验证文件并是必需的。另请注意,< cxf:cxfEndpoint/& gt; 标签末尾的命名空间声明。这些声明是必需的,因为该标签的属性值不支持组合 {namespace}localName 语法。
cxf:cxfEndpoint 元素支持许多其他属性:
| 名称 | 值 |
|---|---|
|
|
此服务实施的端点名称,它将映射到 |
|
|
此服务正在实施的服务名称,它将映射到 |
|
| WSDL 的位置。可以在类路径、文件系统或远程托管上。 |
|
|
要使用的服务模型的 |
|
| 服务发布地址。 |
|
| JAX-WS 端点中使用的总线名称。 |
|
| SEI (Service Endpoint Interface)类的类名称,它可能具有 JSR181 注解。 |
它还支持许多子元素:
| 名称 | 值 |
|---|---|
|
|
此端点的传入拦截器。< |
|
|
此端点的传入故障拦截器。< |
|
|
此端点的传出拦截器。< |
|
|
此端点的传出故障拦截器。< |
|
| 应提供给 JAX-WS 端点的属性映射。请参见以下。 |
|
| JAX-WS 处理程序列表,应当提供给 JAX-WS 端点。请参见以下。 |
|
|
您可以指定要在端点中使用的 |
|
|
您可以指定 |
|
| 保存此端点的拦截器的功能。Bean 或 refs 列表 |
|
| 要使用的端点的架构位置。schemaLocations 列表 |
|
|
此端点使用的服务工厂。这可以通过 Spring < |
您可以找到更高级的示例,它演示了如何在 CXF JAX-WS Configuration 页面上 提供拦截器、属性和处理程序。
您可以使用 cxf:properties 设置 camel-cxf 端点的 dataFormat,并从 spring 配置文件中设置DefaultBus 属性。
<cxf:cxfEndpoint id="testEndpoint" address="http://localhost:9000/router"
serviceClass="org.apache.camel.component.cxf.HelloService"
endpointName="s:PortName"
serviceName="s:ServiceName"
xmlns:s="http://www.example.com/test">
<cxf:properties>
<entry key="dataFormat" value="RAW"/>
<entry key="setDefaultBus" value="true"/>
</cxf:properties>
</cxf:cxfEndpoint>
在 SpringBoot 中,您可以使用 Spring XML 文件配置 camel-cxf,并使用类似以下示例的代码来创建 XML 配置的 Bean:
@ImportResource({
"classpath:spring-configuration.xml"
})
但是,使用配置了 Java 代码的 Bean (如其他示例中所示)是 SpringBoot 中的最佳实践。