本文共 4128 字,大约阅读时间需要 13 分钟。
参考https://blog.csdn.net/chengyuqiang/article/details/90645498
spring.application.name=register-serverserver.port=8800eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://localhost:8800/eureka/
添加
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
完整的pom.xml
4.0.0 com.cntaiping.tpa config-server 0.0.1-SNAPSHOT jar config-server Demo project for Spring Boot com.cntaiping.tpa config 1.0-SNAPSHOT org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-config-server mysql mysql-connector-java org.springframework.boot spring-boot-starter-jdbc
eureka: client: serviceUrl: defaultZone: http://localhost:8800/eureka/spring: profiles: active: jdbc application: name: config-server datasource: url: jdbc:mysql://10.17.12.160:3306/config?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&serverTimezone=GMT%2B8 username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver cloud: config: label: master server: jdbc: trueserver: port: 8300spring.cloud.config.server.jdbc.sql: SELECT key1, value1 from config_properties where APPLICATION=? and PROFILE=? and LABEL=?
添加@EnableEurekaClient
package com.cntaiping.tpa.configserver;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@EnableEurekaClientpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}
4.0.0 com.cntaiping.tpa config-client 0.0.1-SNAPSHOT jar config-client Demo project for Spring Boot com.cntaiping.tpa config 1.0-SNAPSHOT org.springframework.cloud spring-cloud-starter-config org.springframework.cloud spring-cloud-starter-netflix-eureka-client
spring.application.name=config-clienteureka.client.serviceUrl.defaultZone=http://localhost:8800/eureka/spring.profiles.active=dev#spring.cloud.config.uri= http://localhost:8300/spring.cloud.config.fail-fast=truespring.cloud.config.discovery.enabled=truespring.cloud.config.discovery.serviceId=config-serverserver.port=8083
package com.cntaiping.tpa.configclient;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication@EnableEurekaClient@EnableDiscoveryClientpublic class ConfigClientApplication { public static void main(String[] args) { SpringApplication.run(ConfigClientApplication.class, args); }}