spring cloud config client 无法获取到 server 中的值
问题:configserver 可以正常work,client 通过 @Value 无法从server中获取需要的值
configserver代码:
application.properties
management.security.enabled=false
server.port=8888
spring.cloud.config.server.git.uri=https://github.com/pangjianhui/my-config-2
ConfigServerApplication.java
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
build.gradle
buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext {
springCloudVersion = 'Dalston.SR2'
}
dependencies {
compile('org.springframework.cloud:spring-cloud-config-server')
compile('org.tmatesoft.svnkit:svnkit')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR5"
}
}
server 可以正常工作,http://localhost:8888/my-config/test 可以看到返回的内容
{"name":"my-config","profiles":["test"],"label":"master","version":"3d39d7611569de7c6935ae9372965efda6ae9161","state":null,"propertySources":[{"name":"https://github.com/pangjianhui/my-config-2/my-config-test.yml","source":{"myapp.name":"pangjianhui"}}]}
client端
bootstrap.properties
spring.application.name=my-config-test
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=false
build.gradle
buildscript {
ext { springBootVersion = '1.5.2.RELEASE' }
repositories { mavenCentral() }
dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") }
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'configuration-client'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories { mavenCentral() }
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-config')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR5"
}
}
ConfigClientApplication.java
@SpringBootApplication
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}
@RefreshScope
@RestController
class MessageRestController {
@Value("${myapp.name}")
private String message;
@RequestMapping("/message")
String getMessage() {
return this.message;
}
}
client 启动时一直报错:java.lang.IllegalArgumentException: Could not resolve placeholder 'myapp.name' in value "${myapp.name}"
还请各位大虾帮忙看看到底是咋回事,多谢。
相关推荐
spring cloud 中文文档
spring cloud 中文参考文档。
springCloud微服务
Spring Boot has an opinionated view of how to build an application with Spring: for instance it has conventional locations for common configuration file, and endpoints for common management and monitoring tasks. Spring Cloud builds on top of that and adds a few features that probably all components in a system would use or occasionally need.
Apollo安装与SpringBoot集成指南[项目源码]
本文详细介绍了携程Apollo分布式配置中心的安装、SpringBoot集成、动态刷新及与Sentinel整合的完整流程。首先,文章阐述了Apollo的核心特性,包括统一管理多环境配置、配置修改实时生效、版本发布管理、灰度发布及权限审计等。安装部分涵盖了环境依赖(Java 1.8+、MySQL 5.6.5+)、下载1.3版本安装包、创建ApolloPortalDB和ApolloConfigDB两个数据库、通过批处理脚本启动Config Service(端口7070)、Admin Service(端口7080)和Portal(端口7090)三个服务,并强调需修改ServerConfig表地址。SpringBoot集成部分展示了新建Module、配置pom依赖(apollo-client、spring-cloud-context、sentinel相关)、设置yml(指定appId、meta地址、缓存目录、启用bootstrap及eagerLoad)、添加@EnableApolloConfig注解启动类、编写业务Controller和@ConfigurationProperties配置类。动态刷新通过实现ApplicationContextAware接口并监听@ApolloConfigChangeListener事件,发布EnvironmentChangeEvent实现Bean属性热更新。与Sentinel集成时,需注意sentinel-datasource-apollo版本与spring-cloud-starter-alibaba-sentinel一致,通过实现InitializingBean接口在启动时从Apollo读取流控、降级等规则并注册到FlowRuleManager,同时需配置SentinelResourceAspect切面使@SentinelResource注解生效。文章还提供了集群配置(通过系统参数idc区分)、验证配置生效方法(检查缓存目录和日志)以及常见问题排查(如fastjson版本导致父类属性解析失败、缺少SentinelResourceAspect配置)。最后,文章深入解析了Apollo工作原理:Config Service负责配置读取推送,Admin Service负责修改发布,两者通过Eureka注册,Meta Server封装服务发现;配置发布时Admin Service向ReleaseMessage表插入记录,Config Service每秒扫描并通知客户端;客户端通过Http Long Polling长连接(60秒超时)和每5分钟定时拉取双重机制保证配置实时更新。
spring cloud config client 服务配置中心 客户端
spring cloud config client 服务配置中心 客户端 http://knight-black-bob.iteye.com/blog/2356532
Spring Cloud Config(本地配置中心或git配置中心)
Spring Cloud Config(本地配置中心或git配置中心)搭建源码


Web 开发
