forked from yudaocode/SpringBoot-Labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YunaiV
committed
May 3, 2020
1 parent
76a566b
commit fd35d92
Showing
10 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?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>labx-08</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>labx-21-sc-user-service</artifactId> | ||
|
||
<properties> | ||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version> | ||
<spring.cloud.version>Hoxton.SR1</spring.cloud.version> | ||
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version> | ||
</properties> | ||
|
||
<!-- | ||
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。 | ||
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系 | ||
--> | ||
<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> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>${spring.cloud.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-alibaba-dependencies</artifactId> | ||
<version>${spring.cloud.alibaba.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> | ||
|
||
<!-- 引入 Spring Cloud Alibaba Nacos Discovery 相关依赖,将 Nacos 作为注册中心,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...rvice/src/main/java/cn/iocoder/springcloud/labx21/userservice/UserServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.iocoder.springcloud.labx21.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, args); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ce/src/main/java/cn/iocoder/springcloud/labx21/userservice/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cn.iocoder.springcloud.labx21.userservice.controller; | ||
|
||
import cn.iocoder.springcloud.labx21.userservice.dto.UserAddDTO; | ||
import cn.iocoder.springcloud.labx21.userservice.dto.UserDTO; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/user") | ||
public class UserController { | ||
|
||
@GetMapping("/get") | ||
public UserDTO get(@RequestParam("id") Integer id) { | ||
return new UserDTO().setId(id) | ||
.setName("没有昵称:" + id) | ||
.setGender(id % 2 + 1); // 1 - 男;2 - 女 | ||
} | ||
|
||
@PostMapping("/add") | ||
public Integer add(UserAddDTO addDTO) { | ||
return (int) (System.currentTimeMillis() / 1000); // 嘿嘿,随便返回一个 id | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...-user-service/src/main/java/cn/iocoder/springcloud/labx21/userservice/dto/UserAddDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cn.iocoder.springcloud.labx21.userservice.dto; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 用户添加 DTO | ||
*/ | ||
public class UserAddDTO implements Serializable { | ||
|
||
/** | ||
* 昵称 | ||
*/ | ||
private String name; | ||
/** | ||
* 性别 | ||
*/ | ||
private Integer gender; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public UserAddDTO setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Integer getGender() { | ||
return gender; | ||
} | ||
|
||
public UserAddDTO setGender(Integer gender) { | ||
this.gender = gender; | ||
return this; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...-sc-user-service/src/main/java/cn/iocoder/springcloud/labx21/userservice/dto/UserDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cn.iocoder.springcloud.labx21.userservice.dto; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 用户信息 DTO | ||
*/ | ||
public class UserDTO implements Serializable { | ||
|
||
/** | ||
* 用户编号 | ||
*/ | ||
private Integer id; | ||
/** | ||
* 昵称 | ||
*/ | ||
private String name; | ||
/** | ||
* 性别 | ||
*/ | ||
private Integer gender; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public UserDTO setId(Integer id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public UserDTO setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Integer getGender() { | ||
return gender; | ||
} | ||
|
||
public UserDTO setGender(Integer gender) { | ||
this.gender = gender; | ||
return this; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
labx-21/labx-21-sc-user-service/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
spring: | ||
application: | ||
name: user-service # Spring 应用名 | ||
cloud: | ||
nacos: | ||
# Nacos 作为注册中心的配置项 | ||
discovery: | ||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址 | ||
|
||
server: | ||
port: ${random.int[10000,19999]} # 服务器端口。默认为 8080 | ||
# port: 18080 # 服务器端口。默认为 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?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>labx-21</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>labx-21-sc-zuul-demo02-registry</artifactId> | ||
|
||
<properties> | ||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version> | ||
<spring.cloud.version>Hoxton.SR1</spring.cloud.version> | ||
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version> | ||
</properties> | ||
|
||
<!-- | ||
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。 | ||
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系 | ||
--> | ||
<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> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>${spring.cloud.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-alibaba-dependencies</artifactId> | ||
<version>${spring.cloud.alibaba.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- 引入 Spring Cloud Zuul 相关依赖,使用它作为网关,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-zuul</artifactId> | ||
</dependency> | ||
|
||
<!-- 引入 Spring Cloud Alibaba Nacos Discovery 相关依赖,将 Nacos 作为注册中心,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
...demo02-registry/src/main/java/cn/iocoder/springcloud/labx21/zuuldemo/ZuulApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.iocoder.springcloud.labx21.zuuldemo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; | ||
|
||
@SpringBootApplication | ||
@EnableZuulProxy // 开启 Zuul 网关 | ||
public class ZuulApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ZuulApplication.class, args); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
labx-21/labx-21-sc-zuul-demo02-registry/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
server: | ||
port: 8888 | ||
|
||
spring: | ||
application: | ||
name: zuul-application | ||
|
||
# Zuul 配置项,对应 ZuulProperties 配置类 | ||
zuul: | ||
servlet-path: / # ZuulServlet 匹配的路径,默认为 /zuul | ||
# 路由配置项,对应 ZuulRoute Map | ||
routes: | ||
route_yudaoyuanma: | ||
path: /blog/** | ||
url: http://www.iocoder.cn | ||
route_oschina: | ||
path: /oschina/** | ||
url: https://www.oschina.net | ||
route_user_service: | ||
path: /user-serevice/** | ||
service-id: user-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters