feign test

This commit is contained in:
dzj 2024-02-02 07:31:45 +08:00
parent 48b3d32ac6
commit c09fefd44e
4 changed files with 26 additions and 8 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.risesoft</groupId>
<artifactId>demo01</artifactId>
<packaging>jar</packaging>
<packaging>war</packaging>
<version>1.0</version>
<name>demo01</name>
@ -78,12 +78,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--<exclusions>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>-->
</exclusions>
</dependency>
<dependency>
@ -156,8 +156,7 @@
<BP_NATIVE_IMAGE>false</BP_NATIVE_IMAGE>
<BP_JVM_VERSION>21</BP_JVM_VERSION>
</env>
<name>
svn.youshengyun.com:9923/${project.artifactId}-jvm:${project.version}</name>
<name>svn.youshengyun.com:9923/${project.artifactId}-jvm:${project.version}</name>
<publish>true</publish>
</image>
<docker>

View File

@ -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 {

View File

@ -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;
@ -17,9 +20,12 @@ public class UserController {
private final UserRepository userRepository;
public UserController(UserRepository userRepository) {
private final DiscoveryClient client;
public UserController(UserRepository userRepository, DiscoveryClient client) {
super();
this.userRepository = userRepository;
this.client = client;
}
@GetMapping({"", "/"})
@ -27,6 +33,13 @@ public class UserController {
List<String> list = new ArrayList<String>();
list.add("serverName=" + request.getServerName());
list.add("localAddr=" + request.getLocalAddr());
/*List<ServiceInstance> 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;
}

View File

@ -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