I'm teaching myself the Spring Cloud Config Server and having some trouble with injecting the properties into the bean.
So I have a simple Spring Boot Application as config client, just for testing:
@SpringBootApplication
@ConfigurationProperties
public class DemoApplication {
@Value("${greeting}")
static private String greeting;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
System.out.println("The greeting is: " + greeting);
}
}
But the system print:
The greeting is: null
Checking the env endpoint, I actually found the "${greeting}" property was in the environment:
profiles: [ ],
configService:
https://github.com/mstine/config-repo.git/demo.yml: {
greeting: "Webhook"
},
configService:
https://github.com/mstine/config-repo.git/application.yml: {
eureka.instance.hostname: "localhost",
eureka.instance.leaseRenewalIntervalInSeconds: 10,
eureka.instance.metadataMap.instanceId: "${vcap.application.instance_id:${spring.application.name}:${server.port:8080}}",
eureka.client.serviceUrl.defaultZone: "${vcap.services.service-registry.credentials.uri:http://127.0.0.1:8761}/eureka/",
foo: "barnyardAnimal"
},
Notice that in the configService, there is a property called greeting which has value of "Webhook"
I'm new to Spring Framework so I'm wondering didn't I mess up something? Someone suggest I can also access external properties using Environment but I didn't find too much tutorial of how to use it. Any thought?
===================================UPDATE====================================== Adding the code of the config server:
Application.java:
package io.spring.cloud.samples.fortuneteller.configserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
application.yml:
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri:
https://github.com/mstine/config-repo.git
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)