java Spring引导将JAXWS webservice注册为bean
在基于spring boot ws的应用程序中,我按照契约优先的方法创建了一个jax ws Web服务。Web服务已启动,但我无法在Web服务中自动连接其他bean
我如何将我的webservice在春季定义为bean
以下是我的webservice impl类:
@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());
}
}
# 1 楼答案
您不必从SpringBootServletializer扩展配置,也不必重写configure()或onStartup()方法。而且你绝不需要构建实现WebApplicationInitializer的东西。只需执行几个步骤(您也可以在单独的@Configuration类中执行所有步骤,使用@springbootplication的类只需要知道这一步在哪里,例如通过@ComponentScan)
完成了