我尝试学习 SpringBoot SOAP Web 服务实现,但不明白为什么不调用配置方法。配置 bean 如下所示:
package hu.infokristaly.fileservice;
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.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
@Configuration
@EnableWs
public class SOAPWebServiceConfig 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 = "FileUploadServiceWsdl")
public DefaultWsdl11Definition calculatorServiceDefinition(XsdSchema calculatorServiceSchema) {
DefaultWsdl11Definition wsdlDefinition = new DefaultWsdl11Definition();
wsdlDefinition.setPortTypeName("FileUploadServicePort");
wsdlDefinition.setLocationUri("/ws/fileuplaod-service");
wsdlDefinition.setTargetNamespace("http://infokristaly.hu/fileuplaod");
wsdlDefinition.setSchema(fileUplaodServiceSchema());
return wsdlDefinition;
}
@Bean
public XsdSchema fileUplaodServiceSchema() {
return new SimpleXsdSchema(new ClassPathResource("fileupload.xsd"));
}
}
在其他项目中,messageDispatcherServlet / fileUplaodServiceSchema / CalculatorServiceDefinition 方法在启动时调用。
这是我的 Github repo
请帮我找到解决方案。这可能只是一些拼写错误,但我看不出问题所在。 感谢您的所有建议!
如果您的配置位于不同的包中,请在应用程序上使用@ComponentScan,如下所示:
@SpringBootApplication
@ComponentScan(basePackages = {"hu.infokristaly"})
public class ForrasUploadSoapServerApplication {
private static ApplicationContext applicationContext;
public static void main(String[] args) {
SpringApplication.run(ForrasUploadSoapServerApplication.class, args);
}
}