config-server-eureka project

1. File-->new spring project

2.add dependency

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-client
</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>

3.Edit application.yml

server:
port:
#spring cloud config native
spring:
profiles:
active: native
application:
name: config-server-eureka
cloud:
config:
server:
native:
search-locations: /home/smile/workspace-sts/config-repo
#spring cloud config git
#spring:
# application:
# name: config-server-eureka
# cloud:
# config:
# server:
# git:
# uri: http://localhost:3380/root/smile.git
# search-paths: config-repo
# username: root
# password: root123456 eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/

4.program

package com.smile;

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
@EnableEurekaClient
@EnableConfigServer
public class ConfigServerEurekaApplication { public static void main(String[] args) {
SpringApplication.run(ConfigServerEurekaApplication.class, args);
} }

5.Run

visit : http://localhost:8000/smile/config-dev

config-client-eureka

1. File-->new spring project

2.add dependency

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
        <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
spring-boot-starter-actuator refresh 需要用到

3.Edit application.yml

bootstrap.yml

server:
port: spring:
application:
name: config-client-eureka
cloud:
config:
# uri: http://localhost:8000/
discovery:
enabled: true
service-id: config-server-eureka
name: smile
profile: config-dev
# dev 开发环境配置文件 | test 测试环境 | pro 正式环境 smile-config-dev.properties {name}-{profile}.properties eureka:
client:
# registerWithEureka: false
# fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/

application.yml

management:
# server:
# port:
endpoint:
refresh:
enabled: true
endpoints:
web:
exposure:
include:
- info
- health
- refresh

4.program

ConfigClientEurekaApplication
package com.smile;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication
@EnableEurekaClient
@RefreshScope
public class ConfigClientEurekaApplication { public static void main(String[] args) {
SpringApplication.run(ConfigClientEurekaApplication.class, args);
} }
ConfigClientController
package com.smile.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@RefreshScope
public class ConfigClientController { @Value("${name}")
String name;
@Value("${age}")
String age; @RequestMapping("/hello")
public String hello() {
return "name:"+name+",age:"+age;
}
}

5.Run

visit:  http://localhost:8003/hello/

refresh:

update smile-config-dev.properties  age=25--->age=15   save

post  http://localhost:8003/actuator/refresh with firefox browser

visit:  http://localhost:8003/hello/  age is changed

最新文章

  1. 学习笔记:java并发编程学习之初识Concurrent
  2. mysql 根据某些字段之和排序
  3. array_flip() array_merge() array+array的使用总结
  4. 关于Android2.X系统自定义图片圆角BUG的解决
  5. java获取获得Timestamp类型的当前系统时间
  6. webapi 接口规则
  7. lzo压缩格式文件查看
  8. JAVA常识积累
  9. Bitset([HZOI 2015]偏序++)
  10. 【一天一道LeetCode】#117. Populating Next Right Pointers in Each Node II
  11. web测试点总结---UI、兼容、功能、交互、安全、性能、接口测试
  12. 19-05【icloud】照片备份
  13. .Net Core 在 Linux-Centos上的部署实战教程(二)
  14. Matplotlib学习
  15. maven配置(安装&amp;使用&amp;私服)文档
  16. centos7下源码安装mysql5.7.16
  17. hdu 1394 Minimum Inversion Number 逆序数/树状数组
  18. 基础系列(5)—— C#控制语句
  19. Java设计模式 - 单例模式 (懒汉方式和饿汉方式)
  20. 基于canvas实现的fontawesome动态图标

热门文章

  1. Luogu P4095 [HEOI2013]Eden的新背包问题
  2. python 链接mysql 事务
  3. Ajax提交数据后,清空form表单
  4. import cycle not allowed in test
  5. window下git代码推送
  6. 定义Vue-router的动态路由,获取传过来的动态参数
  7. Redis【4】Java Jedis 操作 Redis~
  8. window环境下,php+sphinx+coreseek实现简单的中文全文搜索
  9. PHP实现app唤起支付宝支付代码
  10. phpstudy使用PHP+nginx配置Laravel