18.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/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/cxf/jaxws http://camel.apache.org/schema/cxf/jaxws/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 Bean 元素上指定的 JAX-WS 模式Location
属性。这允许 CXF 验证文件,且是必需的。另请注意 < cxf:cxfEndpoint/&
gt; 标签末尾的命名空间声明。这些声明是必需的,因为此标签的属性值当前不支持组合 {namespace}localName
语法。
cxf:cxfEndpoint
元素支持许多附加属性:
Name | 值 |
---|---|
|
此服务的端点名称,它映射到 |
|
此服务正在实现的服务名称,它映射到 |
| WSDL 的位置。可以位于 classpath、文件系统或远程托管。 |
|
要使用的服务模型的 |
| 服务发布地址。 |
| JAX-WS 端点中使用的总线名称。 |
| SEI (Service Endpoint Interface)类的类名称,该类可以具有 JSR181 注解或不。 |
它还支持多个子元素:
Name | 值 |
---|---|
|
此端点的传入拦截器。< |
|
此端点的传入错误拦截器。< |
|
此端点传出的拦截器。< |
|
此端点传出的故障拦截器。< |
| 应该向 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" })
但是,使用配置了 Bean 的 Java 代码(如其他示例所示)是在 SpringBoot 中最佳实践。