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