当前位置: 首页 > 知识库问答 >
问题:

使用Spring Boot配置SOAP服务时出错

景安翔
2023-03-14

我试图在Spring Boot中使用SOAP web服务。我可以使用Spring MVC应用程序(使用web.xml而不使用Spring boot),但是我在使用Spring boot xml free Setup进行配置时遇到了困难。

下面是我的示例服务的代码,我试图为其生成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);
    }
}

我的Spring Boot配置如下:

@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 localhost:8080/services时,我得到以下错误。

出现错误(类型=找不到,状态=404)。/服务/

[2015-11-07 10:13:00.314]引导-500信息[localhost-startStop-1]--ServletRegistrationBean:将servlet:“wsspringservlet”映射到[/services][2015-11-07 10:13:00.316]引导-500信息[localhost-startStop-1]--ServletRegistrationBean:将servlet:“dispatcher servlet”映射到[/][2015-11-07 10:13:01.405]引导-500信息[main]--Application:在5.642秒内启动应用程序(JVM运行5.961)[2015-11-07 10:13:10.407]引导-500信息[http-nio-8080-exec-1]--[/]:正在初始化Spring FrameworkServlet“dispatcher servlet”[2015-11-07

下面是web.xml配置,它在没有Spring Boot的情况下工作。

<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>

请帮助解决这个问题。

共有1个答案

毛正浩
2023-03-14

我终于设法使服务与Spring Boot一起工作:)。

唯一缺少的代码是导入包含web服务绑定的XML配置。

下面是用于在Spring Boot中配置基于SOAP的服务的更新的WebService配置类。

@Configuration
@EnableWs
@ImportResource("classpath:/applicationContext.xml")
public class WebServiceConfiguration extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean wsServlet(){
        ServletRegistrationBean wsServletBean = new ServletRegistrationBean(new WSSpringServlet(), "/services/*");
        wsServletBean.setLoadOnStartup(1);
        //wsServletBean.setInitParameters(initParameters);
        return wsServletBean;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation=
    "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://jax-ws.dev.java.net/spring/core
    http://jax-ws.java.net/spring/core.xsd
    http://jax-ws.dev.java.net/spring/servlet
    http://jax-ws.java.net/spring/servlet.xsd">

  <wss:binding url="/services/MathService">
    <wss:service><!-- nested bean is of course fine -->
      <ws:service bean="#MathService" />
    </wss:service>
  </wss:binding>

  <wss:binding url="/services/StringService">
    <wss:service><!-- nested bean is of course fine -->
      <ws:service bean="#StringService" />
    </wss:service>
  </wss:binding>

  <!-- this bean implements web service methods -->
  <bean id="MathService" class="com.trial.services.MathOps" />
  <bean id="StringService" class="com.trial.services.StringOps" />
</beans>
 类似资料:
  • 我有HTTPS web服务。我可以使用wsimport生成java类,但当我调用该服务时,我收到以下异常: 调用服务的类如下所示: 有人能帮忙吗。提前谢谢你。

  • 我的项目需求是使用SOAP服务,为此我尝试使用Quarkus。我会用什么Quarkusdependecies来解决这个问题?有什么示例应用程序我可以参考吗? 在Spring中,我们可以使用org.springframework.ws.client.core.support.webserviceGateWaysupport在Quarkus中有类似的东西吗。

  • 我正在尝试使用Jmeter测试一个soap服务。当使用SOAP/XML-RPC请求元素时,服务给出正确的结果。当使用Fiddler执行时,它给出正确的响应(响应代码200)。 但是当我使用Http Request在Jeter上运行相同的服务时。它返回响应代码为500并给出 “请求格式无效:文本/xml。 这在响应数据中。我试着把它改成许多格式,像“应用程序/xml”等等,但是没有用。 [HTTP_

  • 问题内容: 我一直在尝试并尝试学习JQuery,使用AJAX来消费我前一段时间编写的SOAP Web服务。以下是我正在使用的代码: 当前,在Web服务中被调用的方法返回一个类别族数组,其中包含一个类别代码和一个类别描述。由于该方法返回XML,因此我相应地设置了ajax查询。但是,当我运行该应用程序时,我收到一个“错误”警报框- 我确定是什么引起了问题。我知道该Web服务可以正常工作,每天我写的其他

  • 我试图实现一个Spring boot云配置服务器。 我的application.properties文件: 主类: 问题是,当我试图从浏览器url(如http://localhost:8888/client-config/test)点击client config属性时,我被重定向到登录页面。 SpringBootVersion='2.1.6.Release' springcloudversion=

  • 我开发了一个Maven应用程序,当我从Netbeans运行它时,它运行良好,但当我尝试使用jar文件时,它生成了以下错误: 组织。阿帕奇。cxf。服务工厂ServiceConstructionException:无法解析null“”的绑定。 我认为我的文件配置不正确。