首页 > 编程语言 > 详细

springboot整合Apollo

时间:2020-03-15 19:32:43      阅读:58      评论:0      收藏:0      [点我收藏+]

apollo参数信息

技术分享图片

在pom.xml中添加依赖包

        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client</artifactId>
            <version>1.5.1</version>
        </dependency>

修改application.yml以apollo配置参数启动

技术分享图片

apollo参数配置信息

#******apollo参数配置******#
app:
  id: jf-tk-mybatis-1.0
apollo:
  meta: http://localhost:8080
  bootstrap:
    enabled: true
    eagerLoad:
      enabled: true

技术分享图片

在springboot启动类开启Apollo配置,添加注解 @EnableApolloConfig

技术分享图片

创建controller测试Apollo

package com.jeff.tk.mybatis.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWordController {
    
    @Value("${server.port}")
    private String port;
    
    @RequestMapping("hello")
    public String hello() {
        
        return "HelloWord";
    }
    
    @RequestMapping("getPort")
    public String getPort() {
        
        return port;
    }

}

启动springboot项目,打开浏览器访问 http://localhost:9002/getPort

技术分享图片

springboot整合Apollo

原文:https://www.cnblogs.com/jiefu/p/12499329.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!