SPRING-WS没有注册封送员。由春季国际奥委会引起
我有一个运行良好的SOAP客户端服务。 SOAP头和请求在SPRING-WS没有注册封送员。由春季国际奥委会引起,spring,spring-boot,dependency-injection,inversion-of-control,spring-ws,Spring,Spring Boot,Dependency Injection,Inversion Of Control,Spring Ws,我有一个运行良好的SOAP客户端服务。 SOAP头和请求在SOAPConnector类中管理 public class SOAPConnector extends WebServiceGatewaySupport { public Object callWebService(String url, Object request) { // CREDENTIALS and REQUEST SETTINGS... return getWebServiceTe
SOAPConnector类中管理
public class SOAPConnector extends WebServiceGatewaySupport {
public Object callWebService(String url, Object request) {
// CREDENTIALS and REQUEST SETTINGS...
return getWebServiceTemplate().marshalSendAndReceive(url, request, new SetHeader(requestHeader));
}
}
@SpringBootApplication
public class SpringSoapSecurityDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSoapSecurityDemoApplication.class, args);
}
@Bean
public CommandLineRunner lookup(SOAPConnector soapConnector) {
return args -> {
String hotelCode = "****";
FutureBookingSummaryRequest request = new FutureBookingSummaryRequest();
FetchBookingFilters additionalFilters = new FetchBookingFilters();
// Some additionalFilters settings
request.setAdditionalFilters(additionalFilters);
FutureBookingSummaryResponse response = (FutureBookingSummaryResponse) soapConnector
.callWebService("MY WSDL URL", request);
System.err.println(response.getHotelReservations());
};
}
}
在调用主类上的(SoapConnector)服务后,我将收到请求的数据
public class SOAPConnector extends WebServiceGatewaySupport {
public Object callWebService(String url, Object request) {
// CREDENTIALS and REQUEST SETTINGS...
return getWebServiceTemplate().marshalSendAndReceive(url, request, new SetHeader(requestHeader));
}
}
@SpringBootApplication
public class SpringSoapSecurityDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSoapSecurityDemoApplication.class, args);
}
@Bean
public CommandLineRunner lookup(SOAPConnector soapConnector) {
return args -> {
String hotelCode = "****";
FutureBookingSummaryRequest request = new FutureBookingSummaryRequest();
FetchBookingFilters additionalFilters = new FetchBookingFilters();
// Some additionalFilters settings
request.setAdditionalFilters(additionalFilters);
FutureBookingSummaryResponse response = (FutureBookingSummaryResponse) soapConnector
.callWebService("MY WSDL URL", request);
System.err.println(response.getHotelReservations());
};
}
}
到目前为止,它工作正常。
然后我尝试为前一个请求创建一个单独的服务。
BookingService.java
public class BookingService extends WebServiceGatewaySupport {
@Autowired
SOAPConnector soapConnector;
public String getReservations() {
String hotelCode = "****";
FutureBookingSummaryRequest request = new FutureBookingSummaryRequest();
FetchBookingFilters additionalFilters = new FetchBookingFilters();
// Some additionalFilters settings
request.setAdditionalFilters(additionalFilters);
FutureBookingSummaryResponse response = (FutureBookingSummaryResponse) soapConnector
.callWebService("MY WSDL URL", request);
System.err.println(response.getHotelReservations());
};}
为了注入SOAPCONNECTOR,我已将@Service
添加到SOAPCONNECTOR类,并将@Autowired
SOAPCONNECTOR添加到调用它的服务
现在,我调用主类中创建的BookingService
@SpringBootApplication
public class SpringSoapSecurityDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSoapSecurityDemoApplication.class, args);
BookingService bookingService = new BookingService();
bookingService.getReservations();
}
}
SOAPCONNECTOR在收到以下错误时停止工作:
没有马歇尔登记。检查WebServiceTemplate的配置
我很确定这个问题与春季国际奥委会有关,依赖注入。。由于SOAP服务配置良好且工作正常
注意:我已经检查了这个类似的问题
但是@Autowired
并没有解决这个问题。
有什么帮助吗?如果有人面临同样的问题,结果是我错过了bean配置类上的@Configuration注释。正确的选项应如下所示:
@Configuration
public class ConsumerConfig {
private String ContextPath = "somePackage";
private String DefaultUri = "someWsdlURI";
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage> specified in
// pom.xml
marshaller.setContextPath(ContextPath);
return marshaller;
}
@Bean
public SOAPConnector checkFutureBookingSummary(Jaxb2Marshaller marshaller) {
SOAPConnector client = new SOAPConnector();
client.setDefaultUri(DefaultUri);
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
@配置
公共类消费者配置{
私有字符串ContextPath=“somePackage”;
私有字符串DefaultUri=“someWsdlURI”;
@豆子
公共Jaxb2Marshaller-marshaller(){
Jaxb2Marshaller-marshaller=新的Jaxb2Marshaller();
//此包必须与中指定的中的包匹配
//pom.xml
setContextPath(ContextPath);
返回编组员;
}
@豆子
公共SOAPConnector checkFutureBookingSummary(Jaxb2Marshaller){
SOAPConnector客户端=新的SOAPConnector();
setDefaultUri(DefaultUri);
客户机。setMarshaller(marshaller);
客户机。setUnmarshaller(marshaller);
返回客户;
}
问题是您的BookingService
正在扩展WebServiceGatewaySupport
。删除扩展后出现同样的问题!根据跟踪,问题与SOAPConnector有关(位于com.example.SpringSoapSecurityDemo.SOAPConnector.callWebService(SOAPConnector.java:59))您还将自己创建一个新实例,而不是使用spring管理的实例。@M.Deinum您能解释一下吗?BookingService BookingService=new BookingService();
不要这样做。请使用spring管理的实例。