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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM