SpringCould总结 | 第八篇 工程加载配置中心的配置文件

//工程结构

SpringCould总结 | 第八篇 工程加载配置中心的配置文件_第1张图片

//pom文件


	4.0.0

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

	com.spc.configserver.test
	spc-configserver-test
	0.0.1-SNAPSHOT
	jar

	spc-configserver-test
	http://maven.apache.org

	
		UTF-8
		UTF-8
		1.8
		Edgware.RELEASE
	

	
		
			org.springframework.cloud
			spring-cloud-starter-config
		

		
			org.springframework.cloud
			spring-cloud-starter-eureka
		

		
			org.springframework.boot
			spring-boot-starter-actuator
		

		
			org.springframework.boot
			spring-boot-starter-web
		
		
			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
			
		
	

//配置文件

---application.properties 需要配置好注册中心 去取文件

eureka.client.service-url.defaultZone=http://localhost:1000/eureka/
spring.application.name=spc-config-client

spring.cloud.config.label=master
spring.cloud.config.profile=dev
spring.cloud.config.uri= http://localhost:5000/

---bootstrap.properties

#spring.application.name=spc-config-client 是说明去git仓库文件夹下  取个名称叫spc-config-client的配置文件

#xxx.lable=master分支

#xxx.profile=dev 环境类型 spc-config-client-dev.spc-config-client-test 会根据需求取生产类型的测试开发的等

#xxx.uri=配置中心的地址

spring.application.name=spc-config-client

spring.cloud.config.label=master
spring.cloud.config.profile=dev
spring.cloud.config.uri= http://localhost:5000/

//服务类

package com.spc.configserver.client.spc_configserver;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RefreshScope
public class AppController {

	@Value("${spc.config.test}")
	private String name;

	@RequestMapping(value = "/getConfigServerInfo")
	public String getConfigServerInfo() {
		return name;
	}
}
package com.spc.configserver.client.spc_configserver;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableEurekaClient
@SpringBootApplication
public class ConfigClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigClientApplication.class, args);
    }
   
}

//运行结果

SpringCould总结 | 第八篇 工程加载配置中心的配置文件_第2张图片

===本地配置文件仅仅配置了注册中心 端口使用的远程的 ok从远程加成配置文件ok


你可能感兴趣的:(Spring教程,SpringCould总结)