我该如何在Spring中将Web服务定义为bean?
以下是我的Web服务实现类:
@WebService(endpointInterface = "com.foo.bar.MyServicePortType")
@Service
public class MySoapService implements MyServicePortType {
@Autowired
private MyBean obj;
public Res method(final Req request) {
System.out.println("\n\n\nCALLING.......\n\n" + obj.toString()); //obj is null here
return new Res();
}
}
MyServicePortType由Maven从wsdl文件生成。
当我调用此服务(通过SoapUi),它会给出NullPointerException
,因为MyBean对象没有自动装配。
由于我的应用程序是基于Spring Boot构建的,因此没有xml文件。目前,我有一个带有端点配置的sun-jaxws.xml
文件。如何在Spring Boot应用程序中进行以下配置?
<wss:binding url="/hello">
<wss:service>
<ws:service bean="#helloWs"/>
</wss:service>
</wss:binding>
以下是我的SpringBootServletInitializer
类:
@Configuration
public class WebXml extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
return application.sources(WSApplication.class);
}
@Bean
public ServletRegistrationBean jaxws() {
final ServletRegistrationBean jaxws = new ServletRegistrationBean(new WSServlet(), "/jaxws");
return jaxws;
}
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.addListener(new WSServletContextListener());
}
}