diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/.gitignore b/springcloud-alibaba/springcloud-alibaba-nacos-feign/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/pom.xml b/springcloud-alibaba/springcloud-alibaba-nacos-feign/pom.xml new file mode 100644 index 0000000..282f6e6 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/pom.xml @@ -0,0 +1,64 @@ + + 4.0.0 + + + + com.pancm + 0.0.1-SNAPSHOT + springcloud-alibaba-nacos-fegin + jar + pringcloud-alibaba-nacos-fegin + http://maven.apache.org + + + + + UTF-8 + UTF-8 + 1.8 + 5.1.44 + 1.2.3 + 1.7.25 + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 2.2.1.RELEASE + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + 2.2.1.RELEASE + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2.2.1.RELEASE + + + + + + + + diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/.gitignore b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/pom.xml b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/pom.xml new file mode 100644 index 0000000..2d72c6e --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/pom.xml @@ -0,0 +1,85 @@ + + 4.0.0 + + + + com.pancm + 0.0.1-SNAPSHOT + springcloud-alibaba-nacos-feign-consumer1 + jar + springcloud-alibaba-nacos-feign-consumer1 + http://maven.apache.org + + + + + UTF-8 + UTF-8 + 1.8 + 5.1.44 + 1.2.3 + 1.7.25 + 3.0.3 + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 2.2.5.RELEASE + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + 2.2.5.RELEASE + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2.2.5.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + 2.2.5.RELEASE + + + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j-spring-boot-starter.version} + + + + org.projectlombok + lombok + true + + + + + + + + diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/App.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/App.java new file mode 100644 index 0000000..2f1008c --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/App.java @@ -0,0 +1,30 @@ +package com.pancm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +/** + * @Author pancm + * @Description springboot集成nacos配置中心 + * @Date 2024/1/26 + * @Param + * @return + **/ +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class App +{ + private static final Logger logger = LoggerFactory.getLogger(App.class); + public static void main( String[] args ) + { + // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件 + SpringApplication.run(App.class, args); + logger.info("程序启动成功!"); + } +} diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/fegin/CosTestClient.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/fegin/CosTestClient.java new file mode 100644 index 0000000..db6d5fd --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/fegin/CosTestClient.java @@ -0,0 +1,21 @@ +package com.pancm.fegin; + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Map; + +@FeignClient(value = "gdlh-common") +@Component +public interface CosTestClient { + + @PostMapping(value = "/file/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + Map upload(@RequestPart("file") MultipartFile file); +} \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/fegin/TestClient.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/fegin/TestClient.java new file mode 100644 index 0000000..5e0b778 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/fegin/TestClient.java @@ -0,0 +1,12 @@ +package com.pancm.fegin; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; + +@FeignClient(value = "jeecg-nacos-consumer2") +@Component +public interface TestClient { + @GetMapping(value = "/config/getName") + String getName(); +} \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/web/ConfigController.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/web/ConfigController.java new file mode 100644 index 0000000..e0fcbe6 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/web/ConfigController.java @@ -0,0 +1,25 @@ +package com.pancm.web; + +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static org.springframework.web.bind.annotation.RequestMethod.GET; + +/** + * @Author pancm + * @Description 官方示例文档 + * @Date 2024/1/26 + * @Param + * @return + **/ +@RestController +@RequestMapping("config") +public class ConfigController { + + @RequestMapping(value = "/getAge", method = GET) + public String getAge() { + return "18"; + } + +} \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/web/FeignTestController.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/web/FeignTestController.java new file mode 100644 index 0000000..7b26fcb --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/java/com/pancm/web/FeignTestController.java @@ -0,0 +1,41 @@ +package com.pancm.web; + +import com.pancm.fegin.CosTestClient; +import com.pancm.fegin.TestClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Map; + +/** + * @Author pancm + * @Description + * @Date 2024/1/26 + * @Param + * @return + **/ +@RestController +@RequestMapping("test") +public class FeignTestController { + + @Autowired + private TestClient testClient; + + @Autowired + private CosTestClient cosTestClient; + + @GetMapping + public String test() { + return testClient.getName(); + } + + + + @PostMapping("/upload") + public Map upload(@RequestParam("file") MultipartFile multipartFile) { + return cosTestClient.upload(multipartFile); + } + + +} \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/resources/application.yml b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/resources/application.yml new file mode 100644 index 0000000..7a62e40 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/resources/application.yml @@ -0,0 +1,23 @@ +server: + port: 9001 + +spring: + application: + # 服务名称 + name: springcloud-alibaba-nacos-feign-consumer1 + profiles: + active: dev + cloud: + nacos: + config: + server-addr: 127.0.0.1 + group: DEFAULT_GROUP + namespace: gdlh + discovery: + server-addr: 127.0.0.1 + group: DEFAULT_GROUP + namespace: gdlh + config: + import: + - optional:nacos:pancm.yaml + - optional:nacos:pancm-@profile.name@.yaml \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/resources/logback.xml b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/resources/logback.xml new file mode 100644 index 0000000..583ef76 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer1/src/main/resources/logback.xml @@ -0,0 +1,32 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + + ${LOG_HOME}/mylog-%d{yyyy-MM-dd}.%i.txt + + 10MB + 31 + 10GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + + + + + \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/.gitignore b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/pom.xml b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/pom.xml new file mode 100644 index 0000000..6c9842b --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/pom.xml @@ -0,0 +1,71 @@ + + 4.0.0 + + + + com.pancm + 0.0.1-SNAPSHOT + springcloud-alibaba-nacos-feign-consumer2 + jar + springcloud-alibaba-nacos-feign-consumer1 + http://maven.apache.org + + + + + UTF-8 + UTF-8 + 1.8 + 5.1.44 + 1.2.3 + 1.7.25 + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 2.2.5.RELEASE + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + 2.2.5.RELEASE + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2.2.5.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + 2.2.5.RELEASE + + + + + + + + diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/App.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/App.java new file mode 100644 index 0000000..2f1008c --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/App.java @@ -0,0 +1,30 @@ +package com.pancm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +/** + * @Author pancm + * @Description springboot集成nacos配置中心 + * @Date 2024/1/26 + * @Param + * @return + **/ +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class App +{ + private static final Logger logger = LoggerFactory.getLogger(App.class); + public static void main( String[] args ) + { + // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件 + SpringApplication.run(App.class, args); + logger.info("程序启动成功!"); + } +} diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/fegin/TestClient.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/fegin/TestClient.java new file mode 100644 index 0000000..a8955e8 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/fegin/TestClient.java @@ -0,0 +1,19 @@ +package com.pancm.fegin; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * @Author pancm + * @Description 调用jeecg-nacos-consumer1服务 + * @Date 2024/3/12 + * @Param + * @return + **/ +@FeignClient(value = "jeecg-nacos-consumer1") +@Component +public interface TestClient { + @GetMapping(value = "/config/getAge") + String getAge(); +} \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/web/ConfigController.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/web/ConfigController.java new file mode 100644 index 0000000..75b1451 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/web/ConfigController.java @@ -0,0 +1,28 @@ +package com.pancm.web; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static org.springframework.web.bind.annotation.RequestMethod.GET; + +/** + * @Author pancm + * @Description + * @Date 2024/1/26 + * @Param + * @return + **/ +@RestController +@RequestMapping("config") +public class ConfigController { + + + @RequestMapping(value = "/getName", method = GET) + public String getName() { + return "pancm"; + } + + +} \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/web/FeignTestController.java b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/web/FeignTestController.java new file mode 100644 index 0000000..73f3851 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/java/com/pancm/web/FeignTestController.java @@ -0,0 +1,32 @@ +package com.pancm.web; + +import com.pancm.fegin.TestClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static org.springframework.web.bind.annotation.RequestMethod.GET; + +/** + * @Author pancm + * @Description + * @Date 2024/1/26 + * @Param + * @return + **/ +@RestController +@RequestMapping("test") +public class FeignTestController { + + @Autowired + private TestClient testClient; + + + @GetMapping + public String test() { + return testClient.getAge(); + } + + +} \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/resources/application.yml b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/resources/application.yml new file mode 100644 index 0000000..9fcaac5 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/resources/application.yml @@ -0,0 +1,22 @@ +server: + port: 9002 + +spring: + application: + name: springcloud-alibaba-nacos-feign-consumer2 + profiles: + active: dev + cloud: + nacos: + config: + server-addr: 127.0.0.1 + group: DEFAULT_GROUP + namespace: gdlh + discovery: + server-addr: 127.0.0.1 + group: DEFAULT_GROUP + namespace: gdlh + config: + import: + - optional:nacos:pancm.yaml + - optional:nacos:pancm-@profile.name@.yaml \ No newline at end of file diff --git a/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/resources/logback.xml b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/resources/logback.xml new file mode 100644 index 0000000..583ef76 --- /dev/null +++ b/springcloud-alibaba/springcloud-alibaba-nacos-feign/springcloud-alibaba-nacos-feign-consumer2/src/main/resources/logback.xml @@ -0,0 +1,32 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + + ${LOG_HOME}/mylog-%d{yyyy-MM-dd}.%i.txt + + 10MB + 31 + 10GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + + + + + \ No newline at end of file