使用soapweb服务在springboot中加载多个bean

使用soapweb服务在springboot中加载多个bean,soap,spring-boot,wsdl,Soap,Spring Boot,Wsdl,我正在尝试使用SpringBoot编写soap Web服务。我有两个xsd。REL-6-MM7-1-4.xsd,它依赖于SoapEnvelope.xsd 有人能帮我解决这个问题吗 import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.ApplicationContext; import org.springframework.context.a

我正在尝试使用SpringBoot编写soap Web服务。我有两个xsd。REL-6-MM7-1-4.xsd,它依赖于SoapEnvelope.xsd

有人能帮我解决这个问题吗

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
import org.springframework.xml.xsd.XsdSchemaCollection;


@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean(name = "REL-6-MM7-1-4")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchemaCollection xsdSchemaCollection) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("MMSPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4");
        wsdl11Definition.setSchemaCollection(xsdSchemaCollection);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchemaCollection getXsdCollection() {
        return new XsdSchemaCollection() {

            public XsdSchema[] getXsdSchemas() {
                return new XsdSchema[]{new SimpleXsdSchema(new ClassPathResource("REL-6-MM7-1-4.xsd")), new SimpleXsdSchema(new ClassPathResource("SoapEnvelope.xsd"))};
            }

            public XmlValidator createValidator() {
                throw new UnsupportedOperationException();
            }
        };
    }
我试图公开2个bean,但当我启动应用程序时,我得到以下错误


创建在类路径资源[hello/WebServiceConfig.class]中定义的名为“REL-6-MM7-1-4”的bean时出错:调用init方法失败;嵌套异常是java.lang.NullPointerException

请尝试修改您的方法,如下所示:它应该可以工作

    @Bean
    public XsdSchema studentSchema() {
        return new SimpleXsdSchema(new ClassPathResource("school.xsd"));
    }

    @Bean
    public XsdSchema employeeSchema() {
        return new SimpleXsdSchema(new ClassPathResource("employee.xsd"));
    }     


     @Bean
        public XsdSchemaCollection getXsdCollection() {

        return  new XsdSchemaCollection() {

        @Override
        public XmlValidator createValidator() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public XsdSchema[] getXsdSchemas() {
            return new XsdSchema[]{studentSchema(),employeeSchema()}; 
        }};
以下是我所做的:

wsdl11Definition.setSchemaCollection(updateXsds());
....
@Bean
public XsdSchemaCollection updateXsds() throws Exception {

    CommonsXsdSchemaCollection xsds = new CommonsXsdSchemaCollection(
        new ClassPathResource("xsd1.xsd"),
        new ClassPathResource("xsd2.xsd")
        );

    xsds.setUriResolver(new DefaultURIResolver());
    xsds.setInline(true);
    return xsds;
}   

如果您遵循了spring的教程,那么您可以使用多个@Bean方法,但具有相同的corespodent名称

您需要为MessageDispatcherServlet和DefaultWsdl11Definition指定bean名称。Bean名称确定web服务和生成的WSDL文件可用的URL

这样,你可以选择你想要的女巫。 应该是这样的

@Bean(name = "REL-6-MM7-1-4")
public DefaultWsdl11Definition RELWsdl11Definition(XsdSchema schema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setSchema(schema);
    // omitted code... 
}
@Bean(name = "SoapEnvelope")
public DefaultWsdl11Definition SoapEnvelopeWsdl11Definition(XsdSchema schema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    /// omitted code...     
}

@Bean
public XsdSchema REL-6-MM7-1-4Schema() {
    return new SimpleXsdSchema(new ClassPathResource("REL-6-MM7-1-4.xsd"));
}

@Bean
public XsdSchema SoapEnvelopeSchema() {
    return new SimpleXsdSchema(new ClassPathResource("SoapEnvelope.xsd"));
}