springboot整合Apollo

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

posted @ 2020-03-15 18:54  知识追求者  阅读(5006)  评论(0编辑  收藏  举报