start
?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>mypro</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>Test</module>
<module>eureka</module>
<module>config</module>
<module>client</module>
</modules>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.10.RELEASE</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR11</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
eureka服务端
application.yml
server:
port: 8080
eureka:
instance:
hostname: localhost
client:
#实例是否在eureka服务器上注册自己的信息以提供其他服务发现,默认为true
register-with-eureka: false
#此客户端是否获取eureka服务器注册表上的注册信息,默认为true
fetch-registry: false
#抓取服务信息间隔
registry-fetch-interval-seconds: 30
#eureka客户端需要多长时间发送心跳给eureka服务器,表明他仍然或者,默认30秒
#lease-renewal-interval-in-seconds: 5
#eureka服务器在接受到实力的最后一次发出的心跳后,需要等待多久才可以将此实例删除
#lease-expiration-duration-in-seconds: 10
server:
#自我保护模式
enable-self-preservation: false
#清理无效节点,默认60*1000毫秒,即60秒,配合client中lease-renewal-interval-in-seconds,lease-expiration-duration-in-seconds
eviction-interval-timer-in-ms: 1000
#eureka server多级缓存
#第一层是readOnlyCacheMap,然后是readWriteCacheMap,最后从registry进行读取
#其中readOnlyCacheMap会定时从readWriteCacheMap更新数据,而readWriteCacheMap有自己的过期时间
#注册信息缓存更新间隔readWriteCacheMap
response-cache-update-interval-ms: 1000
#缓存过期剔除时间readWriteCacheMap
response-cache-auto-expiration-in-seconds: 60
#关闭缓存readOnlyCacheMap,直接从二级缓存去读取
use-read-only-response-cache: false
启动类
package ws;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class eureka {
public static void main(String[] args) {
SpringApplication.run(eureka.class,args);
}
}
config配置中心
application.yml
server:
port: 8083
eureka:
instance:
instance-id: config-1
client:
service-url:
defaultZone: http://localhost:8080/eureka/
#eureka客户端需要多长时间发送心跳给eureka服务器,表明他仍然或者,默认30秒
lease-renewal-interval-in-seconds: 5
#eureka服务器在接受到实力的最后一次发出的心跳后,需要等待多久才可以将此实例删除
lease-expiration-duration-in-seconds: 10
spring:
application:
name: config
#本地存储
profiles:
active: native
#本地存储路径
cloud:
config:
server:
native:
search-locations: classpath:/config
在resources下新建config目录存储配置文件a.yml
server:
port: 8085
启动类
package ws;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
//@EnableDiscoveryClient:和EnableEurekaClient功能一样,服务注册发现
//是springclound标准注解,EnableEurekaClient只是eureka的
public class config {
public static void main(String[] args) {
SpringApplication.run(config.class,args);
}
}
客户端
bootstrap.yml
客户端要读取远程配置文件,所以要优先加载bootstrap
#bootstrap.yml最先加载
eureka:
instance:
instance-id: client-1
client:
service-url:
defaultZone: http://localhost:8080/eureka/
#eureka客户端需要多长时间发送心跳给eureka服务器,表明他仍然或者,默认30秒
lease-renewal-interval-in-seconds: 5
#eureka服务器在接受到实力的最后一次发出的心跳后,需要等待多久才可以将此实例删除
lease-expiration-duration-in
1413




被折叠的 条评论
为什么被折叠?



