springboot中简单创建webservice服务

简介: 不添加配置类也可以在springboot的启动类了里面发布服务,但是那样的话就不是ioc托管的了,在服务里面就不能注入其他IOC容器里面的对象

添加依赖


   

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

添加配置类


不添加配置类也可以在springboot的启动类了里面发布服务,但是那样的话就不是ioc托管的了,在服务里面就不能注入其他IOC容器里面的对象


ip 用本机IP,端口不能跟当前项目springboot配置文件里面的端口一样


package com.gt.SPYZT.configuration;
import com.gt.SPYZT.webservice.PlaceService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import javax.xml.ws.Endpoint;
/**
 * @author vhukze
 * @date 2022/4/12 14:57
 */
@Configuration
public class WebServiceConfig {
    @Resource
    private PlaceService placeService;
    @Value("${webs.ip-port}")
    private String webs;
    @Bean
    public Endpoint endpoint() {
        String url = "http://" + webs + "/PlaceService";
        System.out.println("服务发布//");
        return Endpoint.publish(url, placeService);
    }
}


创建服务接口


package com.gt.SPYZT.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface PlaceService {
    @WebMethod
    String queryPlace(@WebParam(targetNamespace = "http://impl.webservice.SPYZT.gt.com/", name = "token") String token,
                      @WebParam(targetNamespace = "http://impl.webservice.SPYZT.gt.com/", name = "name") String name);
}

接口实现类

package com.gt.SPYZT.webservice.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gt.SPYZT.entity.po.slave1.TbSpyztServiceinfo;
import com.gt.SPYZT.http.PlaceHttp;
import com.gt.SPYZT.mapper.slave1.TbSpyztServiceinfoMapper;
import com.gt.SPYZT.service.TokenService;
import com.gt.SPYZT.webservice.PlaceService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author vhukze
 * @date 2022/4/12 13:53
 */
@WebService
@Component
public class PlaceServiceImpl implements PlaceService {
    @Resource
    private TbSpyztServiceinfoMapper tbSpyztServiceinfoMapper;
    @Value("${place.name}")
    private String placeName;
    @Value("${place.query-url}")
    private String queryUrl;
    @Override
    @WebMethod
    public String queryPlace(@WebParam(targetNamespace = "http://impl.webservice.SPYZT.gt.com/", name = "token") String token,
                             @WebParam(targetNamespace = "http://impl.webservice.SPYZT.gt.com/", name = "name") String name) {
        return null;
    }
}


命名空间一般就是当前类所在包路径倒过来,一开始没有写命名空间,用postman测试一直拿不到参数值,加上命名空间就可以了


postman测试

请求体


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <queryPlace xmlns="http://impl.webservice.SPYZT.gt.com/">
            <token>meZ0fzvx2uB6BdeDQ7yizmufRZNONer9</token>
            <name></name>
        </queryPlace>
    </soap:Body>
</soap:Envelope>

请求头



示例

相关文章
|
6天前
|
Java API 微服务
【Spring Boot系列】通过OpenAPI规范构建微服务服务接口
【4月更文挑战第5天】通过OpenAPI接口构建Spring Boot服务RestAPI接口
62 0
|
6天前
|
Java 数据处理
【十二】springboot整合WebService
【十二】springboot整合WebService
64 0
|
6天前
|
NoSQL Java Redis
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
382 1
|
6天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的医院核酸检测服务系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的医院核酸检测服务系统的详细设计和实现
40 0
|
6天前
|
JSON 前端开发 安全
Springboot整合邮件服务
Springboot整合邮件服务
|
6天前
|
Java
【十三】springboot整合WebService关于传参数
【十三】springboot整合WebService关于传参数
33 0
|
6天前
|
缓存 NoSQL Java
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
56 0
|
6天前
|
存储 供应链 安全
springboot社区养老服务系统设计与实现
springboot社区养老服务系统设计与实现
|
6天前
|
安全 Java 数据库
基于springboot会员制医疗预约服务管理信息系统
基于springboot会员制医疗预约服务管理信息系统
|
6天前
|
搜索推荐 Java 数据库
springboot基于Web的社区医院管理服务系统
springboot基于Web的社区医院管理服务系统