Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwujing committed Mar 13, 2024
1 parent 53b58a1 commit f090fae
Show file tree
Hide file tree
Showing 19 changed files with 570 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
64 changes: 64 additions & 0 deletions springcloud-alibaba/springcloud-alibaba-nacos-feign/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<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">
<modelVersion>4.0.0</modelVersion>



<groupId>com.pancm</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>springcloud-alibaba-nacos-fegin</artifactId>
<packaging>jar</packaging>
<name>pringcloud-alibaba-nacos-fegin</name>
<url>http://maven.apache.org</url>



<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<mysql-connector>5.1.44</mysql-connector>
<logback>1.2.3</logback>
<slf4j>1.7.25</slf4j>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/>
</parent>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Test 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>

</dependencies>




</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<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">
<modelVersion>4.0.0</modelVersion>



<groupId>com.pancm</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>springcloud-alibaba-nacos-feign-consumer1</artifactId>
<packaging>jar</packaging>
<name>springcloud-alibaba-nacos-feign-consumer1</name>
<url>http://maven.apache.org</url>



<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<mysql-connector>5.1.44</mysql-connector>
<logback>1.2.3</logback>
<slf4j>1.7.25</slf4j>
<knife4j-spring-boot-starter.version>3.0.3</knife4j-spring-boot-starter.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/>
</parent>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Test 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>

<!-- feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>

<!-- Swagger API文档 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j-spring-boot-starter.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

</dependencies>




</project>
Original file line number Diff line number Diff line change
@@ -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("程序启动成功!");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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";
}

}
Original file line number Diff line number Diff line change
@@ -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);
}


}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" >
<property name="LOG_HOME" value="logs"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_HOME}/mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<!-- each file should be at most 10MB, keep 31 days worth of history, but at most 10GB -->
<maxFileSize>10MB</maxFileSize>
<maxHistory>31</maxHistory>
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</Pattern>
</layout>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE" />
</root>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
Loading

0 comments on commit f090fae

Please sign in to comment.