mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
开始 WebService 入门示例
This commit is contained in:
@@ -58,9 +58,9 @@
|
||||
* [《芋道 Spring Boot Dubbo 入门》](http://www.iocoder.cn/Spring-Boot/Dubbo/?github) 对应 [lab-30](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-30)
|
||||
* [《芋道 Spring Boot 声明式调用 Feign 入门》](http://www.iocoder.cn/Spring-Boot/Feign/?github) 对应 [lab-58](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-58)
|
||||
* [《芋道 Spring Boot gRPC 入门》](http://www.iocoder.cn/Spring-Boot/gRPC/?github) 对应 [lab-64](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-64)
|
||||
* [《芋道 Spring Boot Web Services 入门》](http://www.iocoder.cn/Spring-Boot/Web-Services/?github) 对应 [lab-65](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65)
|
||||
* [《芋道 Spring Boot SOFARPC 入门》](http://www.iocoder.cn/Spring-Boot/SOFARPC/?github) 对应 [lab-62](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-62)
|
||||
* [《芋道 Spring Boot Motan 入门》](http://www.iocoder.cn/Spring-Boot/Motan/?github) 对应 [lab-63](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-63)
|
||||
* 《芋道 Spring Boot gRPC 入门》计划中...
|
||||
* 《芋道 Spring Boot RSocket 入门》计划中...
|
||||
|
||||
## 数据访问
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.springboot.lab65.demo.config;
|
||||
|
||||
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserService;
|
||||
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_cxf_ws_demo.UserService;
|
||||
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.springboot.lab65.demo.controller;
|
||||
|
||||
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.*;
|
||||
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_cxf_ws_demo.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="userService" targetNamespace="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo">
|
||||
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-cxf-ws-demo" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="userService" targetNamespace="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-cxf-ws-demo">
|
||||
<wsdl:types>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo" elementFormDefault="unqualified" targetNamespace="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo" version="1.0">
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-cxf-ws-demo" elementFormDefault="unqualified" targetNamespace="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-cxf-ws-demo" version="1.0">
|
||||
<xs:element name="create" type="tns:create"/>
|
||||
<xs:element name="createResponse" type="tns:createResponse"/>
|
||||
<xs:element name="get" type="tns:get"/>
|
||||
<xs:element name="getResponse" type="tns:getResponse"/>
|
||||
<xs:complexType name="create">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="arg0" type="tns:userCreateRequest"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="userCreateRequest">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="gender" type="xs:int"/>
|
||||
<xs:element minOccurs="0" name="name" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="createResponse">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="return" type="tns:userCreateResponse"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="userCreateResponse">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="id" type="xs:int"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="get">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="arg0" type="tns:userGetRequest"/>
|
||||
@@ -27,62 +48,32 @@
|
||||
<xs:element minOccurs="0" name="name" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="create">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="arg0" type="tns:userCreateRequest"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="userCreateRequest">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="gender" type="xs:int"/>
|
||||
<xs:element minOccurs="0" name="name" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="createResponse">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="return" type="tns:userCreateResponse"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="userCreateResponse">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="id" type="xs:int"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
</wsdl:types>
|
||||
<wsdl:message name="getResponse">
|
||||
<wsdl:part element="tns:getResponse" name="parameters"> </wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="get">
|
||||
<wsdl:part element="tns:get" name="parameters"> </wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="create">
|
||||
<wsdl:part element="tns:create" name="parameters"> </wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="createResponse">
|
||||
<wsdl:part element="tns:createResponse" name="parameters"> </wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="get">
|
||||
<wsdl:part element="tns:get" name="parameters"> </wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:message name="getResponse">
|
||||
<wsdl:part element="tns:getResponse" name="parameters"> </wsdl:part>
|
||||
</wsdl:message>
|
||||
<wsdl:portType name="UserService">
|
||||
<wsdl:operation name="get">
|
||||
<wsdl:input message="tns:get" name="get"> </wsdl:input>
|
||||
<wsdl:output message="tns:getResponse" name="getResponse"> </wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="create">
|
||||
<wsdl:input message="tns:create" name="create"> </wsdl:input>
|
||||
<wsdl:output message="tns:createResponse" name="createResponse"> </wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="get">
|
||||
<wsdl:input message="tns:get" name="get"> </wsdl:input>
|
||||
<wsdl:output message="tns:getResponse" name="getResponse"> </wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:portType>
|
||||
<wsdl:binding name="userServiceSoapBinding" type="tns:UserService">
|
||||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||
<wsdl:operation name="get">
|
||||
<soap:operation soapAction="" style="document"/>
|
||||
<wsdl:input name="get">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="getResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="create">
|
||||
<soap:operation soapAction="" style="document"/>
|
||||
<wsdl:input name="create">
|
||||
@@ -92,10 +83,19 @@
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
<wsdl:operation name="get">
|
||||
<soap:operation soapAction="" style="document"/>
|
||||
<wsdl:input name="get">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:input>
|
||||
<wsdl:output name="getResponse">
|
||||
<soap:body use="literal"/>
|
||||
</wsdl:output>
|
||||
</wsdl:operation>
|
||||
</wsdl:binding>
|
||||
<wsdl:service name="userService">
|
||||
<wsdl:port binding="tns:userServiceSoapBinding" name="UserServiceImplPort">
|
||||
<soap:address location="http://127.0.0.1:8080/ws/user"/>
|
||||
<soap:address location="http://127.0.0.1:9090/ws/user"/>
|
||||
</wsdl:port>
|
||||
</wsdl:service>
|
||||
</wsdl:definitions>
|
||||
|
||||
@@ -11,7 +11,7 @@ import javax.xml.ws.Endpoint;
|
||||
@Configuration
|
||||
public class CXFConfig {
|
||||
|
||||
public static final String NAMESPACE_URI = "https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo";
|
||||
public static final String NAMESPACE_URI = "https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-cxf-ws-demo";
|
||||
|
||||
@Bean(name = Bus.DEFAULT_BUS_ID)
|
||||
public SpringBus springBus() {
|
||||
|
||||
@@ -12,7 +12,7 @@ import javax.jws.WebService;
|
||||
@Service
|
||||
@WebService(
|
||||
serviceName = "userService", // 服务名称
|
||||
targetNamespace = CXFConfig.NAMESPACE_URI // WSDL 命名空间
|
||||
targetNamespace = CXFConfig.NAMESPACE_URI // Namespace 命名空间
|
||||
)
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
|
||||
@@ -39,12 +39,6 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Feign 相关依赖 -->
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
<version>11.0</version>
|
||||
</dependency>
|
||||
<!-- 引入 Feign SOAP 拓展的依赖 -->
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
|
||||
1
lab-65/《芋道 Spring Boot Web Services 入门》.md
Normal file
1
lab-65/《芋道 Spring Boot Web Services 入门》.md
Normal file
@@ -0,0 +1 @@
|
||||
<http://www.iocoder.cn/Spring-Boot/Web-Services/?github>
|
||||
49
lab-66/lab-66-spring-data-solr/pom.xml
Normal file
49
lab-66/lab-66-spring-data-solr/pom.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>lab-66</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-66-spring-data-solr</artifactId>
|
||||
|
||||
<properties>
|
||||
<!-- 依赖相关配置 -->
|
||||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
|
||||
<!-- 插件相关配置 -->
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- 自动化配置 Spring Data Solr -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-solr</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 方便等会写单元测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
package cn.iocoder.springboot.lab15.springdatasolr;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package cn.iocoder.springboot.lab15.springdatasolr.dataobject;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.solr.core.mapping.Indexed;
|
||||
import org.springframework.data.solr.core.mapping.SolrDocument;
|
||||
|
||||
@SolrDocument(collection = "new_core")
|
||||
public class SolrProductDO {
|
||||
|
||||
/**
|
||||
* ID 主键
|
||||
*/
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
@Indexed(value = "name")
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Indexed(value = "description")
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
@Indexed(value = "cid")
|
||||
private Integer cid;
|
||||
/**
|
||||
* 分类名
|
||||
*/
|
||||
@Indexed(value = "category_name")
|
||||
private String categoryName;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public SolrProductDO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SolrProductDO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public SolrProductDO setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getCid() {
|
||||
return cid;
|
||||
}
|
||||
|
||||
public SolrProductDO setCid(Integer cid) {
|
||||
this.cid = cid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCategoryName() {
|
||||
return categoryName;
|
||||
}
|
||||
|
||||
public SolrProductDO setCategoryName(String categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SolrProductDO{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", cid=" + cid +
|
||||
", categoryName='" + categoryName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.iocoder.springboot.lab15.springdatasolr.repository;
|
||||
|
||||
import cn.iocoder.springboot.lab15.springdatasolr.dataobject.SolrProductDO;
|
||||
import org.springframework.data.solr.repository.SolrCrudRepository;
|
||||
|
||||
public interface ProductRepository extends SolrCrudRepository<SolrProductDO, Integer> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
spring:
|
||||
data:
|
||||
solr:
|
||||
host: 'http://127.0.0.1:8983/solr'
|
||||
repositories:
|
||||
enabled: true
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.iocoder.springboot.lab15.springdatasolr.repository;
|
||||
|
||||
import cn.iocoder.springboot.lab15.springdatasolr.Application;
|
||||
import cn.iocoder.springboot.lab15.springdatasolr.dataobject.SolrProductDO;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class ProductRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
private ProductRepository productRepository;
|
||||
|
||||
@Test // 插入一条记录
|
||||
public void testInsert() {
|
||||
SolrProductDO product = new SolrProductDO();
|
||||
product.setId(1); // 一般 Solr 的 ID 编号,使用 DB 数据对应的编号。这里,先写死
|
||||
product.setName("芋道源码");
|
||||
product.setDescription("我只是一个描述");
|
||||
product.setCid(2);
|
||||
product.setCategoryName("技术");
|
||||
productRepository.save(product);
|
||||
}
|
||||
|
||||
// 这里要注意,如果使用 save 方法来更新的话,必须是全量字段,否则其它字段会被覆盖。
|
||||
// 所以,这里仅仅是作为一个示例。
|
||||
@Test // 更新一条记录
|
||||
public void testUpdate() {
|
||||
SolrProductDO product = new SolrProductDO();
|
||||
product.setId(1);
|
||||
product.setCid(2);
|
||||
product.setCategoryName("技术-Java");
|
||||
productRepository.save(product);
|
||||
}
|
||||
|
||||
@Test // 根据 ID 编号,删除一条记录
|
||||
public void testDelete() {
|
||||
productRepository.deleteById(1);
|
||||
}
|
||||
|
||||
@Test // 根据 ID 编号,查询一条记录
|
||||
public void testSelectById() {
|
||||
Optional<SolrProductDO> userDO = productRepository.findById(1);
|
||||
System.out.println(userDO.isPresent());
|
||||
}
|
||||
|
||||
@Test // 根据 ID 编号数组,查询多条记录
|
||||
public void testSelectByIds() {
|
||||
Iterable<SolrProductDO> users = productRepository.findAllById(Arrays.asList(1, 4));
|
||||
users.forEach(System.out::println);
|
||||
}
|
||||
|
||||
}
|
||||
19
lab-66/pom.xml
Normal file
19
lab-66/pom.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>labs-parent</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-66</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>lab-66-spring-data-solr</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user