SpringBoot2.0之整合Apollo

SpringBoot2.0之整合Apollo

Spring Boot客户端对接阿波罗服务器端

  

核心源码都在这个压缩包里面

封装好了环境 运行shell脚本就ok了

 

 下面进入到本地maven仓库:

远程仓库apollo的jar包 只能打包到本地或者公司的私服了

 

首先引入pom:


		org.springframework.boot
		spring-boot-starter-parent
		2.0.1.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
		Finchley.RC1
	
	
		
			org.springframework.boot
			spring-boot-starter
		
		
			org.springframework.cloud
			spring-cloud-starter-netflix-eureka-client
		
		
			org.springframework.boot
			spring-boot-starter-web
			
		

		
		
			com.ctrip.framework.apollo
			apollo-client
			1.0.0
		
		
			com.ctrip.framework.apollo
			apollo-core
			1.0.0
		


		
			org.projectlombok
			lombok
			true
		
		
			com.alibaba
			fastjson
			1.2.3
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		
			
				org.springframework.cloud
				spring-cloud-dependencies
				${spring-cloud.version}
				pom
				import
			
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
			
				org.apache.maven.plugins
				maven-compiler-plugin
				
					1.8
					1.8
				
			
			
				org.apache.maven.plugins
				maven-resources-plugin
				3.0.1
				
					
						copy-conf
						package
						
							copy-resources
						
						
							UTF-8
							${project.build.directory}/ext/conf
							
								
									ext/conf
									
										logback.xml
									
									true
								
							
						
					
				
			
			
				org.jacoco
				jacoco-maven-plugin
				0.7.5.201505241946
				
					
						default-prepare-agent
						
							prepare-agent
						
					
					
						default-prepare-agent-integration
						
							prepare-agent-integration
						
					
				
			
			
				com.spotify
				docker-maven-plugin
				0.4.3
				
					hy_uav_gateway
					src/main/docker
					
						
							/
							${project.build.directory}
							${project.build.finalName}.jar
							ext/conf/logback.xml
						
					
				
			
		
	

	
		
			spring-milestones
			Spring Milestones
			https://repo.spring.io/milestone
			
				false
			
		
	

  远程仓库没有:

SpringBoot2.0之整合Apollo_第1张图片

 

 

 SpringBoot2.0之整合Apollo_第2张图片

把解压出来的 apollo master

SpringBoot2.0之整合Apollo_第3张图片

 

 SpringBoot2.0之整合Apollo_第4张图片

运行成功

 

然后 maven update下创建的maven 项目

本地仓库就有了

 

yml:

server:
  port: 8001
spring:
  application:
    name: toov5_apl
eureka:
  client:
    service-url:
      defaultZone: http://192.168.212.162:8080/eureka

 什么信息需要上传到配置中心的?

   经常需要变化 修改的!

修改环境

创建并且修改 /opt/settings/server.properties(Mac/Linux)文件,

C:\opt\settings\server.properties(Windows)文件,设置env为DEV:

 

默认读取这个文件

创建apollo-env配置文件信息

source下面: apollo-env.properties 

local.meta=http://192.168.91.7:8080
dev.meta=http://192.168.91.7:8080
fat.meta=${fat_meta}
uat.meta=${uat_meta}
lpt.meta=${lpt_meta}
pro.meta=${pro_meta}  

source下面:

创建 META-INF 

在META-INF文件夹创建app.properties  指定appid

 SpringBoot2.0之整合Apollo_第5张图片

与之对应

app.id=app_client_toov5

 

当前目录:

  SpringBoot2.0之整合Apollo_第6张图片

apollo自己整合了eureka  所以我们也需要写配置文件时候 写上它的端口好和ip

 

下面写代码:

package com.toov5.api.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 IndexController {
   
    @Value("${toov5-test:ins}")  //默认值test 读不到的情况下 就是ins
    private String toov5;
    
    @RequestMapping("/getName")
    public String getName() {
        return toov5;
    }

   启动类:

package com.toov5.api.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;


@EnableApolloConfig
@SpringBootApplication
public class App {
  public static void main(String[] args) {
    SpringApplication.run(App.class, args);
}
}

app.properties

app.id=app_client_toov5  

apollo-env.properties

  

local.meta=http://192.168.91.7:8080
dev.meta=http://192.168.91.7:8080
fat.meta=${fat_meta}
uat.meta=${uat_meta}
lpt.meta=${lpt_meta}
pro.meta=${pro_meta}

  

 yml:

server:
  port: 8001
spring:
  application:
    name: toov5_a
eureka:
  client:
    service-url:
      defaultZone: http://192.168.91.7:8080/eureka

  

启动访问:

SpringBoot2.0之整合Apollo_第7张图片

 一定要记得 设置 dev 环境配置

 

 

你可能感兴趣的:(Apollo,SpringBoot)