Home > Software engineering >  Can not load configure property source from config server
Can not load configure property source from config server

Time:12-30

I have an issue related to load configuration property from config-server. Please you kindly check and advise me how can I load those configure.
Thank you.

JDK: 11
Spring: 2.6.2
Spring cloud: 2021.0.0

Main

@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

application.properties
  message="HELLO WORLD"

Rest Controller


@RestController
@RefreshScope
public class RestMainController {
    @Value("${message}")
    private String message;

    @GetMapping("/index")
    public String index() {
        return "------->"   message;
    }
}
{
  "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\""
      }
    }
  ]
}

Error Message

Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'message' in value "${message}"

CodePudding user response:

You dont need to keep value for message key in "",

application.properties
  message=HELLO WORLD

CodePudding user response:

on Git, your file name should be demo.properties because you set "spring.application.name=demo".

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
  • Related