Using config value from Config Server
Hi, I have gradle project in intellij called as Config Server application. I tried to bind the config server application with Github with below code:
So that i can read value form config file that is in Github.
spring:
cloud:
config:
server:
git:
uri: https://github.com/anilallewar/microservices-basics-cloud-config
in application.yml file i have some value that i want to use with below code:
@Configuration
@RestController
public class test {
@Value("${mail.domain}")
private String ss1;
private static final Logger logger = LoggerFactory.getLogger(test.class);
@RequestMapping(value = "/", method = RequestMethod.GET)
public String Hello(){
logger.info("logging statement test " + ss1);
return ss1;
}
}
However, whenever i am trying to run this project in Intellij, getting below error:
2018-05-30 19:04:23.645 DEBUG 15204 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/charsets.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/deploy.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/access-bridge-64.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/cldrdata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/dnsns.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/jaccess.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/jfxrt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/localedata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/nashorn.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/sunec.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/sunjce_provider.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/sunmscapi.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/sunpkcs11.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/ext/zipfs.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/javaws.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/jce.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/jfr.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/jfxswt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/jsse.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/management-agent.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/plugin.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/resources.jar, file:/C:/Program%20Files/Java/jdk1.8.0_162/jre/lib/rt.jar, file:/C:/git/ConfigServerlocally/out/production/classes/, 2.1/ch.qos.logback/logback-core/1.1.11/88b8df40340eed549fb07e2613879bf6b006704d/logback-core-1.1.11.jar, file:/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202018.1.1/lib/idea_rt.jar]
2018-05-30 19:04:23.665 ERROR 15204 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'test': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'mail.domain' in value "${mail.domain}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at com.anilallewar.microservices.config.ConfigApplication.main(ConfigApplication.java:44) [classes/:na]
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'mail.domain' in value "${mail.domain}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:831) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
... 17 common frames omitted
Process finished with exit code 1
Please sign in to leave a comment.
Look like application is unable to find such property in the classpath. Make sure you are adding properties to classpath correctly, see e.g. https://stackoverflow.com/q/28307237/2000323
The issue does not seem directly related to IDE functionality to you might get better help asking the question on the Spring-related forums or SO.