From c09fefd44eae60e17078ef2c8803e0383fd947f8 Mon Sep 17 00:00:00 2001 From: dingzhaojun Date: Fri, 2 Feb 2024 07:31:45 +0800 Subject: [PATCH] feign test --- pom.xml | 9 ++++----- .../java/net/risesoft/demo/Demo01Application.java | 2 ++ .../risesoft/demo/controller/UserController.java | 15 ++++++++++++++- src/main/resources/application.yml | 8 ++++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 17562f6..80f0414 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 net.risesoft demo01 - jar + war 1.0 demo01 @@ -78,12 +78,12 @@ org.springframework.boot spring-boot-starter-web - + @@ -156,8 +156,7 @@ false 21 - - svn.youshengyun.com:9923/${project.artifactId}-jvm:${project.version} + svn.youshengyun.com:9923/${project.artifactId}-jvm:${project.version} true diff --git a/src/main/java/net/risesoft/demo/Demo01Application.java b/src/main/java/net/risesoft/demo/Demo01Application.java index 8b138ac..90ec535 100644 --- a/src/main/java/net/risesoft/demo/Demo01Application.java +++ b/src/main/java/net/risesoft/demo/Demo01Application.java @@ -2,7 +2,9 @@ package net.risesoft.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +@EnableDiscoveryClient @SpringBootApplication public class Demo01Application { diff --git a/src/main/java/net/risesoft/demo/controller/UserController.java b/src/main/java/net/risesoft/demo/controller/UserController.java index 9fdcb86..25e1372 100644 --- a/src/main/java/net/risesoft/demo/controller/UserController.java +++ b/src/main/java/net/risesoft/demo/controller/UserController.java @@ -2,7 +2,10 @@ package net.risesoft.demo.controller; import java.util.ArrayList; import java.util.List; +import java.util.Random; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -16,10 +19,13 @@ import net.risesoft.demo.repository.UserRepository; public class UserController { private final UserRepository userRepository; + + private final DiscoveryClient client; - public UserController(UserRepository userRepository) { + public UserController(UserRepository userRepository, DiscoveryClient client) { super(); this.userRepository = userRepository; + this.client = client; } @GetMapping({"", "/"}) @@ -27,6 +33,13 @@ public class UserController { List list = new ArrayList(); list.add("serverName=" + request.getServerName()); list.add("localAddr=" + request.getLocalAddr()); + + /*List instances = client.getInstances("demo01"); + ServiceInstance selectedInstance = instances.get(new Random().nextInt(instances.size())); + list.add("serviceId=" + selectedInstance.getServiceId()); + list.add("host=" + selectedInstance.getHost()); + list.add("port=" + selectedInstance.getPort());*/ + return list; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b690265..d71f081 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,7 +7,7 @@ management: exposure: include: '*' server: - port: 7099 + port: 8081 servlet: context-path: /demo01 encoding: @@ -33,7 +33,7 @@ spring: compatibility-verifier: enabled: false consul: - host: ${CONSUL_HOST:consul} + host: ${CONSUL_HOST:localhost} port: ${CONSUL_PORT:8500} discovery: register-health-check: true @@ -72,6 +72,10 @@ spring: allow-bean-definition-overriding: true allow-circular-references: false lazy-initialization: false + keep-alive: true + threads: + virtual: + enabled: true docker: compose: enabled: false