首页 > 编程语言 > 详细

springboot集成apollo

时间:2020-09-30 19:59:50      阅读:39      评论:0      收藏:0      [点我收藏+]

1. 没有apollo服务端的,可参考https://www.cnblogs.com/pageBlog/p/13754664.html先搭建个服务端

2. 登录apollo管理平台创建项目

技术分享图片

 

 

技术分享图片

 

3. 增加配置

 技术分享图片

 

 

4. 新增一个springboot的web工程

5. 增加依赖

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

6. application.properties中增加如下配置(这里如果写在bootstrap.properties会不起作用)

app.id=10000
apollo.meta=http://192.168.92.130:8080
# will inject ‘application‘ namespace in bootstrap phase
apollo.bootstrap.enabled = true

7. 增加个controller

package com.example.page.test.springapollo.controller;

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

/**
 * @author page
 * @since 2020/9/30 16:28
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Value("${hello}")
    private String hello;

    @RequestMapping("/sayHello")
    public String sayHello() {
        System.out.println("sayHello begin, hello " + hello);
        return "hello " + hello;
    }
}

8. 启动工程,调用接口

技术分享图片

 

springboot集成apollo

原文:https://www.cnblogs.com/pageBlog/p/13755781.html

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