mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
soul 示例项目
This commit is contained in:
@@ -263,6 +263,9 @@
|
||||
* [《芋道 Spring Boot 服务容错 Hystrix 入门》](http://www.iocoder.cn/Spring-Boot/Hystrix/?github)的[「6. 集成到 Dubbo」](#)小节
|
||||
* [《芋道 Spring Cloud Netflix 服务容错 Hystrix 入门》](http://www.iocoder.cn/Spring-Cloud/Netflix-Hystrix/?github)的[「10. 集成到 Dubbo」](#)小节
|
||||
|
||||
**[Resilience4j](http://www.iocoder.cn/categories/Resilience4j/?github)**
|
||||
* [《芋道 Spring Boot 服务容错 Resilience4j 入门》](http://www.iocoder.cn/Spring-Boot/Resilience4j/?github)的[「10. 集成到 Dubbo」](#)小节
|
||||
|
||||
## 分布式事务
|
||||
|
||||
**[Seata](http://www.iocoder.cn/Seata/install/?github)**
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
|
||||
<!-- <artifa ctId>spring-boot-starter-data-jpa</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?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-60-soul-dubbo-demo</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-60-soul-dubbo-demo-user-service-api</artifactId>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
package cn.iocoder.springboot.lab60.userservice.api;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
String getUser(Integer id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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-60-soul-dubbo-demo</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-60-soul-dubbo-demo-user-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
|
||||
</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>
|
||||
<!-- 引入用户服务 API 包 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<artifactId>lab-60-soul-dubbo-demo-user-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Spring Boot 依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Dubbo 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>2.7.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>2.7.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 使用 Nacos 作为注册中心 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-registry-nacos</artifactId>
|
||||
<version>2.7.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Soul 针对 Dubbo 的集成的依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>soul-client-apache-dubbo</artifactId>
|
||||
<version>2.1.2-RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab60.userservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class UserServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UserServiceApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.iocoder.springboot.lab60.userservice.service;
|
||||
|
||||
import cn.iocoder.springboot.lab60.userservice.api.UserService;
|
||||
import org.dromara.soul.client.common.annotation.SoulClient;
|
||||
|
||||
@org.apache.dubbo.config.annotation.Service(version = "1.0.0")
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
@SoulClient(path = "/user/get", desc = "获得用户详细")
|
||||
public String getUser(Integer id) {
|
||||
return "User:" + id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类
|
||||
dubbo:
|
||||
# Dubbo 应用配置
|
||||
application:
|
||||
name: user-service # 应用名
|
||||
# Dubbo 注册中心配
|
||||
registry:
|
||||
address: nacos://127.0.0.1:8848 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
|
||||
# address: zookeeper://127.0.0.1:2181 # 注册中心地址。多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
|
||||
# Dubbo 服务提供者协议配置
|
||||
protocol:
|
||||
port: -1 # 协议端口。使用 -1 表示随机端口。
|
||||
name: dubbo # 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档
|
||||
# Dubbo 服务提供者配置
|
||||
provider:
|
||||
timeout: 1000 # 【重要】远程服务调用超时时间,单位:毫秒。默认为 1000 毫秒,胖友可以根据自己业务修改
|
||||
# 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者
|
||||
scan:
|
||||
base-packages: cn.iocoder.springboot.lab60.userservice.service
|
||||
|
||||
soul:
|
||||
# Soul 针对 Dubbo 的配置项,对应 DubboConfig 配置类
|
||||
dubbo:
|
||||
admin-url: http://127.0.0.1:9095
|
||||
context-path: /demo-api
|
||||
app-name: demo-service
|
||||
20
lab-60/lab-60-soul-dubbo-demo/pom.xml
Normal file
20
lab-60/lab-60-soul-dubbo-demo/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?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-60</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-60-soul-dubbo-demo</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>lab-60-soul-dubbo-demo-user-service-api</module>
|
||||
<module>lab-60-soul-dubbo-demo-user-service</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
47
lab-60/lab-60-soul-spring-boot-demo/pom.xml
Normal file
47
lab-60/lab-60-soul-spring-boot-demo/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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-60</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-60-soul-spring-boot-demo</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
|
||||
</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>
|
||||
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 Soul 针对 SpringMVC 的集成的依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>soul-client-springmvc</artifactId>
|
||||
<version>2.1.2-RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab60;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.iocoder.springboot.lab60.controller;
|
||||
|
||||
import org.dromara.soul.client.common.annotation.SoulClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/demo")
|
||||
public class DemoController {
|
||||
|
||||
@GetMapping("/get")
|
||||
@SoulClient(path = "/demo/get", desc = "示例接口")
|
||||
public String get(@RequestParam("id") Integer id) {
|
||||
return "DEMO:" + id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
soul:
|
||||
# Soul 针对 SpringMVC 的配置项,对应 SoulHttpConfig 配置类
|
||||
http:
|
||||
admin-url: http://127.0.0.1:9095
|
||||
context-path: /demo-api
|
||||
app-name: demo-service
|
||||
zookeeper-url: 127.0.0.1:2181
|
||||
20
lab-60/pom.xml
Normal file
20
lab-60/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?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-60</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>lab-60-soul-dubbo-demo</module>
|
||||
<module>lab-60-soul-spring-boot-demo</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
3
pom.xml
3
pom.xml
@@ -53,7 +53,8 @@
|
||||
<!-- <module>lab-40</module>-->
|
||||
<!-- <module>lab-41</module>-->
|
||||
<module>lab-42</module>
|
||||
<!-- <module>lab-43</module>-->
|
||||
<module>lab-60</module>
|
||||
<!-- <module>lab-43</module>-->
|
||||
<!-- <module>lab-44</module>-->
|
||||
<!-- <module>lab-45</module>-->
|
||||
<!-- <module>lab-46</module>-->
|
||||
|
||||
Reference in New Issue
Block a user