【发布时间】:2015-10-26 17:39:44
【问题描述】:
我想将 Spring 应用程序迁移到 Spring Boot。原始应用程序由几个 maven 模块组成,我想重用现有模块之一。我要重用的模块是生成的 cxf Web 服务客户端。它在应用程序的pom.xml 中链接,如下所示:
<dependency>
<groupId>generated.package</groupId>
<artifactId>cxf-service-adapter</artifactId>
<version>1.0</version>
</dependency>
在该模块中生成的GenCxfService 接口如下所示
@WebService(targetNamespace = "https://the-domain/the-service/", name = "genCxfService")
@XmlSeeAlso({ObjectFactory.class})
public interface GenCxfService {
// the anotated web service methods
// ....
}
我需要 Web 服务客户端接口 GenCxfService 由 Spring Boot 管理,以便我可以将其传递给 Spring Security AuthenticationProvider。
好吧,我认为这没什么大不了的。我从模块中取出已编译的cxf-service-adapter-1.0.jar,将其放入自己的项目内存储库中,并尝试将java配置设置为@autowire bean。首先我是这样尝试的:
import generated.package.GenCxfService;
...
@ComponentScan({"generated.package.*","my.package.*"})
...
@Bean
public MyAuthenticationProvider myAuthenticationProvider() {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("https://the-domain/the-service/");
factory.setServiceClass(GenCxfService.class);
GenCxfService genCxfService = (GenCxfService) factory.create();
return new my.package.authentication.MyAuthenticationProvider(userDAO, genCxfService);
}
这在运行时给了我以下异常:
javax.xml.ws.soap.SOAPFaultException: Could not find conduit initiator for address: https://the-domain/the-service/the-wsdl.asmx and transport: http://schemas.xmlsoap.org/soap/http
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:161)
at com.sun.proxy.$Proxy126.validateMyUser(Unknown Source)
at my.package.authentication.MyAuthenticationProvider.authenticate(MyAuthenticationProvider.java:47)
我以为我只是有一个错误的 java 配置,并尝试通过重用原始项目模块中的现有 xml 配置来解决问题,使用
@ImportResource({"classpath:web-service.xml"})
带有xml文件:
<jaxws:client id="genCxfService"
serviceClass="generated.package.GenCxfService"
address="https://the-domain/the-service/the-wsdl.asmx">
</jaxws:client>
<bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<cxf:bus>
<cxf:inInterceptors>
<ref bean="logInbound" />
</cxf:inInterceptors>
<cxf:inFaultInterceptors>
<ref bean="logInbound" />
</cxf:inFaultInterceptors>
</cxf:bus>
这是在cxf documentation (Configuring a Spring Client Option 1) 中配置客户端的方式。尽管如此,我仍然遇到同样的错误。
我做错了什么?
更新
将 cxf-rt-transports-http 添加到 pom 中就可以了:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
</dependency>
谁能解释为什么缺少库不会在启动期间而是在运行时引发异常?
提前致谢。
【问题讨论】:
标签: web-services maven dependency-injection spring-boot cxf