SPRING-WS没有注册编组.由SPRING IOC引起 [英] SPRING-WS No marshaller registered. Caused by SPRING IOC

查看:147
本文介绍了SPRING-WS没有注册编组.由SPRING IOC引起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的SOAP客户端服务. SOAP标头和请求在SOAPConnector class中进行管理.

I have a SOAP client service which works fine. The SOAP headers and request are managed in a SOAPConnector class.

public class SOAPConnector extends WebServiceGatewaySupport {

    public Object callWebService(String url, Object request) {
        // CREDENTIALS and REQUEST SETTINGS...
        return getWebServiceTemplate().marshalSendAndReceive(url, request, new SetHeader(requestHeader));
    }
}

main Class上调用我的(SoapConnector)服务后,我正在接收请求的数据.

I'm receiving the requested Data once I call my (SoapConnector) service on the main Class.

@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

Then I've tried to create a separate service for the previous request. 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,我在SOAPCONNECTOR类中添加了@Service,并在调用它的服务中添加了@Autowired SOAPConnector soapConnector
现在,一旦我在主类中调用了创建的BookingService

In order to inject the SOAPCONNECTOR I've added @Service to SOAPCONNECTOR class , and @Autowired SOAPConnector soapConnector to the service calling it
Now once I call the created BookingService in the main class

@SpringBootApplication
public class SpringSoapSecurityDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringSoapSecurityDemoApplication.class, args);
        BookingService bookingService = new BookingService();
        bookingService.getReservations();
    } 
}

SOAPCONNECTOR停止工作,我收到以下错误:

The SOAPCONNECTOR stops working an I receive the following error :

没有编组员注册.检查WebServiceTemplate的配置.

No marshaller registered. Check configuration of WebServiceTemplate.

我非常确定这是与SPRING IOC有关的问题,依赖注入..由于SOAP服务已正确配置并且可以正常工作.

I'm pretty sure that's this issue is related to SPRING IOC , dependecy injection .. Since the SOAP service is well configured and working..

注意:我已经检查了这个类似的问题 正在消耗SOAP Web服务错误(没有注册封送处理程序.请检查WebServiceTemplate的配置),但是@Autowired不能解决问题. 有帮助吗?

Note : I've checked this similiar question Consuming a SOAP web service error (No marshaller registered. Check configuration of WebServiceTemplate) but the @Autowired didn't solve the issue. Any help ?

推荐答案

万一有人遇到相同的问题,事实证明我错过了bean配置类上的@Configuration批注.正确的外观应如下所示:

In case someone is facing the same issue, it turned out that I've missed the @Configuration annotation on the beans configuration class. The right one should look like the following:

    @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;
    }

这篇关于SPRING-WS没有注册编组.由SPRING IOC引起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆