我试图在Spring启动时使用SOAP Web服务。我能够使用Spring MVC应用程序(使用web.xml而不使用spring引导),但我坚持使用Spring启动xml免费安装程序进行配置。使用Spring启动配置SOAP服务时出错
下面是我的示例服务的代码,我正在尝试生成wsdl。
@WebService(serviceName="AddService", targetNamespace="http://add.sample.net/service/", name="addService", portName="adService")
public class MathOps extends SpringBeanAutowiringSupport {
@WebMethod
public int add(int a, int b){
return (a+b);
}
}
我的春天,引导配置是如下:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
application.logStartupInfo(true);
return application.sources(Application.class);
}
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.addListener(new ContextLoaderListener());
servletContext.addListener(new WSServletContextListener());
}
@Bean
public ServletRegistrationBean wsServlet(){
ServletRegistrationBean wsServletBean = new ServletRegistrationBean(new WSSpringServlet(), "/services");
return wsServletBean;
}
}
当我打的URL本地主机:8080 /服务,我得到下面的错误。
出现意外错误(type = Not Found,status = 404)。 /services/
似乎为URL映射/服务,dispatcherServlet正在从下面的日志中调用,而不是WSSpringServlet。
[2015年11月7日10:13:00.314]引导 - 500 INFO [本地主机 - startStop-1] --- ServletRegistrationBean:映射的servlet: 'WSSpringServlet' 为[/服务] [2015-11- 07 10:13:00.316] boot - 500 INFO [localhost-startStop-1] --- ServletRegistrationBean:将servlet:'dispatcherServlet'映射到[/] [2015-11-07 10:13:01.405] boot - 500 INFO [main] ---应用程序:启动应用程序在5.642秒(JVM运行5.961) [2015-11-07 10:13:10.407] boot - 500 INFO [http-nio-8080-exec-1] --- [/]:初始化Spring FrameworkServlet'dispatcherServlet' [2015-11-07 10:13:10.408] boot - 500 INFO [http-nio-8080-exec-1] --- DispatcherServlet:FrameworkServlet'dispatcherServlet':初始化已启动 [2015-11-07 10:13:10.425] boot-500 INFO [http-nio-8080-exec-1] --- DispatcherServlet:FrameworkServlet'dispatcherServlet':初始化17ms内完成
Web下面是没有弹簧启动的.xml配置。
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>MyTest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyTest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>TestService</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>TestService</servlet-name>
<url-pattern>/services</url-pattern>
</servlet-mapping>
</web-app>
请帮助解决这个问题。
删除监听器的注册,并只留下servlet。您可能需要设置'order'属性,以便在调度程序servlet之前进行注册。 –