首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从配置服务器加载配置属性源

无法从配置服务器加载配置属性源
EN

Stack Overflow用户
提问于 2021-12-29 08:46:42
回答 2查看 242关注 0票数 0

我有一个与从配置服务器加载配置属性相关的问题。请您检查并建议我如何加载这些配置。

谢谢。

JDK: 11

春季: 2.6.2

春云: 2021.0.0

代码语言:javascript
复制
@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigServerDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerDemoApplication.class, args);
    }

}

/resource/application.properties

spring.application.name=demo
spring.cloud.config.enabled=true
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.uri=https://gitlab.com/mama/test-config-server.git

Git Repo

代码语言:javascript
复制
application.properties
  message="HELLO WORLD"

Rest控制器

代码语言:javascript
复制
@RestController
@RefreshScope
public class RestMainController {
    @Value("${message}")
    private String message;

    @GetMapping("/index")
    public String index() {
        return "------->" + message;
    }
}
代码语言:javascript
复制
{
  "name": "demo",
  "profiles": [
    "default"
  ],
  "label": null,
  "version": "59ff5bd35093e6791eb8f6fb7e23d7915b21e565",
  "state": null,
  "propertySources": [
    {
      "name": "https://gitlab.com/mama/test-config-server.git/application.properties",
      "source": {
        "message": "\"HELLO WORLD\""
      }
    }
  ]
}

错误消息

代码语言:javascript
复制
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'message' in value "${message}"
EN

回答 2

Stack Overflow用户

发布于 2021-12-29 08:58:29

您不需要在"“中保留message键的值,

代码语言:javascript
复制
application.properties
  message=HELLO WORLD
票数 0
EN

Stack Overflow用户

发布于 2021-12-29 09:20:16

在Git上,您的文件名应该是demo.properties,因为您设置了"spring.application.name=demo“。

代码语言:javascript
复制
The HTTP service has resources in the following form:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70517085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档