commit 1b47f5a1225ca699ca768a246cefa7d5fa410fff Author: dingzhaojun Date: Fri Feb 2 07:33:42 2024 +0800 feign client diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..94f480d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4532bdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Build and Release Folders +target/ + +# Eclipse +.settings/ +*.classpath +*.project +*.factorypath + +# IntelliJ IDEA +.idea +*.iml + +# vscode +.vscode + +# JRebel +rebel.xml + +# macOS +.DS_Store + +# svn +.svn/ + +# vue +kernel-standard/ +node_modules/ \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1f3b8a8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,112 @@ + + + 4.0.0 + net.risesoft + demo01-client + war + 1.0 + demo01-client + + + org.springframework.boot + spring-boot-starter-parent + 3.2.2 + + + + + UTF-8 + 21 + + + + + gitea + https://svn.youshengyun.com:3000/api/packages/risesoft/maven + + + gitea + https://svn.youshengyun.com:3000/api/packages/risesoft/maven + + + + + + + org.springframework.cloud + spring-cloud-dependencies + 2023.0.0 + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.cloud + spring-cloud-starter-consul-discovery + + + + jakarta.servlet + jakarta.servlet-api + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + net.risesoft.demo.Demo01Application + + + false + 21 + + svn.youshengyun.com:9923/${project.artifactId}-jvm:${project.version} + true + + + + publisher + 83204585 + + + + + + + + diff --git a/src/main/java/net/risesoft/demo/FeignClientApplication.java b/src/main/java/net/risesoft/demo/FeignClientApplication.java new file mode 100644 index 0000000..65764ed --- /dev/null +++ b/src/main/java/net/risesoft/demo/FeignClientApplication.java @@ -0,0 +1,17 @@ +package net.risesoft.demo; + +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 FeignClientApplication { + + public static void main(String[] args) { + SpringApplication.run(FeignClientApplication.class, args); + } + +} diff --git a/src/main/java/net/risesoft/demo/ServletInitializer.java b/src/main/java/net/risesoft/demo/ServletInitializer.java new file mode 100644 index 0000000..d703c81 --- /dev/null +++ b/src/main/java/net/risesoft/demo/ServletInitializer.java @@ -0,0 +1,16 @@ +package net.risesoft.demo; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.web.WebApplicationInitializer; + +public class ServletInitializer extends SpringBootServletInitializer implements WebApplicationInitializer { + + @Override + protected SpringApplicationBuilder configure(final SpringApplicationBuilder builder) { + setRegisterErrorPageFilter(false); + builder.sources(FeignClientApplication.class); + return builder; + } + +} \ No newline at end of file diff --git a/src/main/java/net/risesoft/demo/client/ClientA.java b/src/main/java/net/risesoft/demo/client/ClientA.java new file mode 100644 index 0000000..6d3910b --- /dev/null +++ b/src/main/java/net/risesoft/demo/client/ClientA.java @@ -0,0 +1,13 @@ +package net.risesoft.demo.client; + +import java.util.List; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +@FeignClient(name = "demo01", contextId = "ClientA", path="/demo01") +public interface ClientA { + + @GetMapping("/") + List hosts(); +} diff --git a/src/main/java/net/risesoft/demo/controller/mainController.java b/src/main/java/net/risesoft/demo/controller/mainController.java new file mode 100644 index 0000000..53cc90b --- /dev/null +++ b/src/main/java/net/risesoft/demo/controller/mainController.java @@ -0,0 +1,22 @@ +package net.risesoft.demo.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import net.risesoft.demo.client.ClientA; + +@RestController +@RequestMapping +public class mainController { + + @Autowired + ClientA client; + + @RequestMapping("/") + public List hosts() { + return client.hosts(); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..98b2237 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,59 @@ +management: + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: '*' +server: + port: 8081 + servlet: + context-path: /demo01-client + encoding: + charset: UTF-8 + enabled: true + force: true + force-request: true + force-response: true + session: + cookie: + http-only: true + secure: false + timeout: 300 + tracking-modes: COOKIE + shutdown: graceful + ssl: + enabled: false + +spring: + application: + name: demo01-client + cloud: + compatibility-verifier: + enabled: false + consul: + host: ${CONSUL_HOST:localhost} + port: ${CONSUL_PORT:8500} + discovery: + register-health-check: true + healthCheckPath: ${server.servlet.context-path}/actuator/health + healthCheckInterval: 15s + metadata: + metrics: ${server.servlet.context-path}/actuator/prometheus + springboot: true + isv: risesoft + tags: + - traefik.enable=true + - traefik.http.routers.demo01.rule=PathPrefix(`/users`,`/actuator`) + prefer-ip-address: true + instance-id: ${spring.application.name}:${spring.application.instance-id:${random.value}} + service-name: ${spring.application.name} + main: + allow-bean-definition-overriding: true + allow-circular-references: false + lazy-initialization: false + keep-alive: true + threads: + virtual: + enabled: false