diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 7526064..2fd39f8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,11 +2,13 @@ + - + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..4a50c20 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml new file mode 100644 index 0000000..02b915b --- /dev/null +++ b/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 2c45ded..eea3247 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/docs/00.环境部署.md b/docs/00.环境部署.md new file mode 100644 index 0000000..06d592a --- /dev/null +++ b/docs/00.环境部署.md @@ -0,0 +1,51 @@ +### Nacos +#### 从 github 上下载对应环境的安装包 +> https://github.com/alibaba/nacos/releases + +解压后执行 +```shell +cd nacos/bin +``` + +##### linux +```shell +# 默认为 cluster 集群模式 +# sh startup.sh +sh startup.sh -m standalone +``` + +##### windows +单机模式 +```shell +# 默认为 cluster 集群模式 +# startup.cmd +startup.cmd -m standalone +``` + +##### 默认账号密码为 nacos nacos + +#### 单机模式下配置 mysql +先在数据库中创建数据库 +并执行 **conf/mysql-schema.sql** 初始化数据库表 + +编辑 conf/application.properties +修改 Config Module Related Configurations 部分 +```properties +spring.sql.init.platform=mysql + +### Count of DB: +db.num=1 + +### Connect URL of DB: +db.url.0=jdbc:mysql://[数据库ip]:[端口]/[数据库名]?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC +db.user.0=[数据库账号] +db.password.0=[数据库密码] + +### Connection pool configuration: hikariCP +db.pool.config.connectionTimeout=30000 +db.pool.config.validationTimeout=10000 +db.pool.config.maximumPoolSize=20 +db.pool.config.minimumIdle=2 +``` + + diff --git a/pom.xml b/pom.xml index 4357202..2b657b8 100644 --- a/pom.xml +++ b/pom.xml @@ -15,4 +15,49 @@ project-01 + + + 1.8 + 2.4.4 + 2020.0.2 + 2021.1 + 1.18.26 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + diff --git a/project-01/consumer/pom.xml b/project-01/consumer/pom.xml new file mode 100644 index 0000000..ba6a632 --- /dev/null +++ b/project-01/consumer/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + cn.skcks.study.springcloud + project-01 + 1.0-SNAPSHOT + + + cn.skcks.study.springcloud.project01 + consumer + + + 8 + 8 + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.projectlombok + lombok + + + diff --git a/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/Application.java b/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/Application.java new file mode 100644 index 0000000..161558f --- /dev/null +++ b/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/Application.java @@ -0,0 +1,15 @@ +package cn.skcks.study.springcloud.project01; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/controller/ConsumerController.java b/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/controller/ConsumerController.java new file mode 100644 index 0000000..1bcb8d3 --- /dev/null +++ b/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/controller/ConsumerController.java @@ -0,0 +1,18 @@ +package cn.skcks.study.springcloud.project01.controller; + +import cn.skcks.study.springcloud.project01.feign.ProviderClient; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + + +@AllArgsConstructor +@RestController +public class ConsumerController { + private final ProviderClient providerClient; + + @GetMapping("/hi") + public String hi(){ + return providerClient.hi("feign"); + } +} diff --git a/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/feign/ProviderClient.java b/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/feign/ProviderClient.java new file mode 100644 index 0000000..f02a862 --- /dev/null +++ b/project-01/consumer/src/main/java/cn/skcks/study/springcloud/project01/feign/ProviderClient.java @@ -0,0 +1,12 @@ +package cn.skcks.study.springcloud.project01.feign; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@FeignClient(value = "project-01-provider") +public interface ProviderClient { + @GetMapping("/hi") + String hi(@RequestParam(value = "name",defaultValue = "Shikong",required = false) String name); +} diff --git a/project-01/consumer/src/main/resources/application.yml b/project-01/consumer/src/main/resources/application.yml new file mode 100644 index 0000000..c8780be --- /dev/null +++ b/project-01/consumer/src/main/resources/application.yml @@ -0,0 +1,11 @@ +server: + port: 8763 + +spring: + application: + name: project-01-consumer + + cloud: + nacos: + discovery: + server-addr: 10.10.10.20:8848 diff --git a/project-01/pom.xml b/project-01/pom.xml index bdb0023..c9c74a0 100644 --- a/project-01/pom.xml +++ b/project-01/pom.xml @@ -11,5 +11,11 @@ project-01 + pom + + + provider + consumer + diff --git a/project-01/provider/pom.xml b/project-01/provider/pom.xml new file mode 100644 index 0000000..cc6fe14 --- /dev/null +++ b/project-01/provider/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + cn.skcks.study.springcloud + project-01 + 1.0-SNAPSHOT + + + cn.skcks.study.springcloud.project01 + provider + + + 1.8 + 1.8 + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + diff --git a/project-01/provider/src/main/java/cn/skcks/study/springcloud/project01/Application.java b/project-01/provider/src/main/java/cn/skcks/study/springcloud/project01/Application.java new file mode 100644 index 0000000..90b4421 --- /dev/null +++ b/project-01/provider/src/main/java/cn/skcks/study/springcloud/project01/Application.java @@ -0,0 +1,27 @@ +package cn.skcks.study.springcloud.project01; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +@EnableDiscoveryClient +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Value("${server.port}") + String port; + + @GetMapping("/hi") + public String hi(@RequestParam(value = "name", defaultValue = "Shikong",required = false) String name) { + return "hello " + name + ", i'm provider ,my port:" + port; + + } +} diff --git a/project-01/provider/src/main/resources/application.yml b/project-01/provider/src/main/resources/application.yml new file mode 100644 index 0000000..c907ecf --- /dev/null +++ b/project-01/provider/src/main/resources/application.yml @@ -0,0 +1,10 @@ +server: + port: 8762 +spring: + application: + name: project-01-provider + + cloud: + nacos: + discovery: + server-addr: 10.10.10.20:8848 diff --git a/project-01/src/main/java/cn/skcks/study/springcloud/Main.java b/project-01/src/main/java/cn/skcks/study/springcloud/Main.java deleted file mode 100644 index 743b018..0000000 --- a/project-01/src/main/java/cn/skcks/study/springcloud/Main.java +++ /dev/null @@ -1,4 +0,0 @@ -package cn.skcks.study.springcloud; - -public class Main { -}