spring config client端bootstrap.yml
cloud:
config:
name: microservicecloud-config-client #需要从git上读取的资源名称,注意没有yml后缀名
profile: dev #本次访问的配置项
label: master
uri: http://config-3344.com:3344 #本微服务启动后先去找3344号服务,通过SpringCloudConfig获取git的服务地址
类ConfigClientRest
@RestController
public class ConfigClientRest {
@Value("${spring.application.name}")
private String applicationName;
@Value("${eureka.client.service-url.defaultZone}")
private String eurekaServers;
@Value("${server.port}")
private String port;
@RequestMapping("/config")
public String getConfig(){
String str = "applicationName: " + applicationName
+ "\t eurekaServers: " + eurekaServers
+ "\t port: " + port;
System.out.println("*****str: " + str);
return "applicationName: " + applicationName
+ "\t eurekaServers: " + eurekaServers
+ "\t port: " + port;
}
}
码云上面microservicecloud-config-client.yml
spring:
profiles:
active:
- dev
---
server:
port: 8201
spring:
profiles: dev
application:
name: microservicecloud-config-client
eureka:
client:
service-url:
defaultZone: http://eureka-dev.com:7001/eureka/
---
server:
port: 8202
spring:
profiles: test
application:
name: microservicecloud-config-client
eureka:
client:
service-url:
defaultZone: http://eureka-test.com:7001/eureka/
springcloud config server端application.xml
server:
port: 3344
spring:
application:
name: microservicecloud-config
cloud:
config:
server:
git:
uri: git@gitee.com:lb20162501306/mricoservicecloud-config.git #码云上git仓库地址
报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configClientRest': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.application.name' in value "${spring.application.name}"