java - 正在注册 jaxws :client as a Spring bean in Spring Boot Framework

标签 java spring spring-mvc spring-boot cxf

我看到一个 java 项目,其中使用 WSDL2Java 命令生成 Web 服务客户端。该项目还包含一个带有以下配置的 spring.xml :

<jaxws:client
    id = "com.xyz.connector"
    serviceClass = "com.xyz.XYZServicePort"
    address = "<endpoint url from config>"
    bus="XYZServiceBus">
</jaxws:client>
<bean id = "XYZPasswordCallback" class = "com.xyz.ClientPasswordCallback">
    <property name = "password" value = "<password from config>"/>
</bean>
<bean id = "logInbound" class = "org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id = "logOutbound" class = "org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<cxf:bus bus="XYZServiceBus">
    <cxf:inInterceptors>
        <ref bean = "logInbound"/>
    </cxf:inInterceptors>
    <cxf:outInterceptors>
        <ref bean = "logOutbound"/>
        <bean class = "org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
            <constructor-arg>
                <map>
                    <entry key = "action" value = "UsernameToken"/>
                    <entry key = "addUTElements" value = "Unique ID Created"/>
                    <entry key = "user" value = "<user id from config>"/>
                    <entry key = "passwordType" value = "PasswordText"/>
                    <entry key = "passwordCallbackRef" value-ref = "XYZServiceBus"/>
                </map>
            </constructor-arg>
        </bean>
    </cxf:outInterceptors>
    <cxf:outFaultInterceptors>
        <ref bean = "logOutbound"/>
    </cxf:outFaultInterceptors>
    <cxf:inFaultInterceptors>
        <ref bean = "logInbound"/>
    </cxf:inFaultInterceptors>
</cxf:bus>

有一个 Java 类文件,上面列出的 spring.xml 已使用下面的注释加载。

@ImportResource({ /*"classpath:config.xml",*/ "classpath*:META-INF/application-context.xml", "classpath*:META-INF/spring.xml" })

XYZServicePort 使用类中的注释 Autowiring 。然后,XYZServicePort 用于调用服务公开的操作。

与 spring.xml 相关的 xml 片段是添加到使用 wsdl2java 命令生成的 Web 服务客户端项目的唯一配置文件。我在 spring.xml 中没有看到任何配置,也没有在将 XYZServicePort 定义为 bean 的代码中看到任何注释。 spring.xml 中的 xml 片段是否以某种方式将 XYZServicePort 转换为 spring bean?

最佳答案

<强> <jaxws:client>可以在客户端使用。您将为它提供一个 bean 名称、服务接口(interface)和服务 URL,CXF 将创建一个具有指定名称的 bean,实现服务接口(interface),并调用远程 SOAP 服务,该服务需要在 Spring 中注入(inject)到该客户端需要调用的位置。

有关更多详细信息,请参阅以下 URL:

http://cxf.apache.org/docs/writing-a-service-with-spring.html

http://cxf.apache.org/docs/jax-ws-configuration.html

希望这会有所帮助!

关于java - 正在注册 jaxws :client as a Spring bean in Spring Boot Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32085875/

相关文章:

java - 如何在java中访问文件系统?

ajax - Spring - 在 Ajax 请求失败后成功登录后重定向到链接

java - Spring Web Mvc 配置初始化

java - 如何在没有强制转换的情况下迭代 SetMultimap 中的集合?

java - 在跳过要求使用 Scanner 输入字符串的行之前出现 StringIndexOutOfBoundsException

spring - 如何使用 spring-security-oauth2 支持消费应用程序可配置身份验证提供程序

java - 在 Thymeleaf 中对实体使用 'select' 标签

java - 反转并比较字符串

java - 在 Google App Engine 中使用 Java,如何从 int r、g、b 值的数组中制作 BMP 图像?

spring - 自定义 Cassandra 转换器