这里使用的Maven,Java 8来操作的。

Maven相关代码为:

    <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>wsdl4j</groupId><artifactId>wsdl4j</artifactId><version>1.6.1</version></dependency><dependency><groupId>org.springframework.ws</groupId><artifactId>spring-ws-core</artifactId><version>3.0.8.RELEASE</version></dependency></dependencies>

buid里面要添加一个插件:

    <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>jaxb2-maven-plugin</artifactId><version>2.5.0</version><executions><execution><id>xjc</id><goals><goal>xjc</goal></goals></execution></executions><configuration><sources><source>${project.basedir}/src/main/resources/countries.xsd</source></sources></configuration></plugin></plugins></build>

这里要创建一个xml,通过这个xml生成对应的Object

这里countries.xsd为:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://it1995.com/example/demo"targetNamespace="http://it1995.com/example/demo" elementFormDefault="qualified"><xs:element name="getCountryRequest"><xs:complexType><xs:sequence><xs:element name="name" type="xs:string"/></xs:sequence></xs:complexType></xs:element><xs:element name="getCountryResponse"><xs:complexType><xs:sequence><xs:element name="country" type="tns:country"/></xs:sequence></xs:complexType></xs:element><xs:complexType name="country"><xs:sequence><xs:element name="name" type="xs:string"/><xs:element name="population" type="xs:int"/><xs:element name="capital" type="xs:string"/><xs:element name="currency" type="tns:currency"/></xs:sequence></xs:complexType><xs:simpleType name="currency"><xs:restriction base="xs:string"><xs:enumeration value="GBP"/><xs:enumeration value="EUR"/><xs:enumeration value="PLN"/></xs:restriction></xs:simpleType>
</xs:schema>

其中target/jaxb/com/it1995/example/demo是这样生成的:

其中这个文件路径是xsd文件xmlns:tns,targetNamespace

xmlns:tns和targetNamespace生成对应的包。

下面是关于各个文件的分

CountryRepository.java:存储城市的数据,为webService提供数据。

CountryEndpoint.java:创建服务端,需要使用到POJO类及少量的Spring WS注解处理SOAP的请求。

其中:

其中NAMESPACE_URL为XML里面的xmlns:tns,targetNamespace。其中里面涉及几个注解:

@Endpoint:将此类注册为Spring WS的候选类,用于接收SOAP消息;

@PayloadRoot:这个也是Spring WS的注解作用在方法上其中namespace填写xml的namespace,而localpart填写xml中作用的方法;

@RequestPayload:方法中参数的注解,将SOAP传过来的数据映射到参数中;

@ResponsePayload:返回响应数据。

WebServiceConfig.java:配置Spring WS相关的配置Bean

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {@Beanpublic ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {MessageDispatcherServlet servlet = new MessageDispatcherServlet();servlet.setApplicationContext(applicationContext);servlet.setTransformWsdlLocations(true);return new ServletRegistrationBean(servlet, "/ws/*");}@Bean(name = "countries")public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();wsdl11Definition.setPortTypeName("CountriesPort");wsdl11Definition.setLocationUri("/ws");wsdl11Definition.setTargetNamespace("http://it1995.com/example/demo");wsdl11Definition.setSchema(countriesSchema);return wsdl11Definition;}@Beanpublic XsdSchema countriesSchema() {return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));}
}

Spring WS有自己的servlet用于处理SOAP消息。上面的MessageDispatcherServlet十分重要,他将ApplicatoinContext注入到了MessageDispatcherServlet。并且这个Bean并不会影响Spring 的默认Bean。

程序运行截图如下:

源码打包下载地址:

https://github.com/fengfanchen/Java/tree/master/SOAPWebProduction

Spring Boot文档阅读笔记-构建SOAP的web Service服务相关推荐

  1. Spring Boot文档阅读笔记-构建SOAP的web Service Client

    同样,这里是使用Maven及Java8 同样Maven添加如下依赖: <dependency><groupId>wsdl4j</groupId><artifa ...

  2. Spring Boot文档阅读笔记-构建Restful风格的WebService客户端

    对应的maven如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...

  3. Spring Boot文档阅读笔记-构建Restful风格的WebService

    Maven代码如下: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...

  4. Spring Boot文档阅读笔记-对Securing a Web Application解析

    首先创建一个非安全的Web应用 这个应用包含两个页面,一个是home页面,一个是"Hello,World"页面.home页面使用Thymeleaf,相关代码如下: <!DOC ...

  5. Spring Boot文档阅读笔记-how-to-implement-2-way-ssl-using-spring-boot

    two-way-ssl需要12次握手(除去TCP的三次握手),如下图: 双向认证过程: 1.客户端发送ClientHello消息,告诉服务端要使用SSL. 2.客户端发送ServerHello的响应, ...

  6. Spring Boot文档阅读笔记-EhCache的使用

    这里要先注意2个概念: buffer和cache,很多人会讲这两个概念混用.但其实这是两个概念! buffer:一般是指存储临时数据的实体.只能读写一次,对于程序员来说buffer是可见的,比如TCB ...

  7. Spring Boot文档阅读笔记-Spring Boot @Bean解析

    利用SpringBoot的@Bean创建一个简单的Bean. Spring的@Bean注解是放在方法上的,带上这个注解的方法会被Spring容器管理.并且这个方法要返回一个值(对象),这个值和对象会被 ...

  8. Spring Boot文档阅读笔记-对Messaging with RabbitMQ解析

    此篇教程以Rabbitmq作为消息队列服务端,使用Spring Boot产生和发布消息. 使用Spring AMQP的RabbitTemplate发布消息,使用MessageListenerAdapt ...

  9. Spring Boot文档阅读笔记-@SpringBootApplication官方解析与实例(1.5.19)

    目录 官方解析 博主例子 官方解析 @SpringBootApplication有如下3个特点: 1. @EnableAutoConfiguration: 能够启动Spring Boot的自动配置机制 ...

最新文章

  1. C++——智能指针——auto_ptr、shared_ptr、unique_ptr
  2. Java不同场景加载不同类_[改善Java代码]不同的场景使用不同的泛型通配符
  3. hdu 3549 Flow Problem(最大流模板题)
  4. 用“谬论”指挥研究方向数十年,是谁让“老年痴呆”至今仍是绝症?
  5. echarts 中 symbol 自定义图片
  6. 飞船向上飞pygame用k_up_十分钟就能用Python教你开发出一个迷你打飞机的游戏
  7. 在线YAML转XML工具
  8. 上海java工作经验与薪资_Java硕士京东工作1年,跳槽后他期望薪资26K,大家感觉他可以吗...
  9. 他们每天都在为梦想排除万难,那你呢?
  10. 关于软考的一些事,你知道吗?
  11. 企业员工人事管理系统(数据库课设)
  12. SpringCound-Alibaba
  13. 定时器的用法以及pwm的调速
  14. 阿里P4 - P14技能要求及对应薪资曝光
  15. Kafka生产者、消费者的消息可靠性方案实现
  16. 接口用例设计从哪些方面考虑
  17. Ansys2020R2的Fluent网格重排问题(reorder)
  18. 中国IT女性生存状态写实(转)
  19. NGUI图集分解 切割
  20. 台式计算机的日常保养,台式电脑怎么保养

热门文章

  1. CentOS 5安装GIT的基本命令
  2. Oracle SQL Loader的详细语法
  3. HTML P不能包含块级元素(包括自身)
  4. pl sql代码提示手动提示设置
  5. 从72小时到1分钟,数据如何快速响应业务需求?
  6. 还在被Excel报表折磨?学会这个进阶工具,报表开发不是事儿
  7. 实用、酷炫的可视化,你用10小时,同事用10分钟,差距在哪?
  8. 用3种方式解决复杂报表
  9. 多媒体技术基础及应用
  10. 从socket中读取一行语句