2017-08-18 317 views
0

運行config-client時出現錯誤。直接從彈簧指南不起作用的簡單事情。從配置的客戶端服務Spring雲配置服務 - 客戶端不能正常工作

2017-08-18 13:44:31.194 ERROR 12548 --- [   main] o.s.boot.SpringApplication    : Application startup failed 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.restController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'message' in value "${message}" 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.sprin 

RestController 

@RefreshScope 
@org.springframework.web.bind.annotation.RestController 
public class RestController { 
    @Value("${message}") 
    private String message; 

    @RequestMapping("/message") 
    String getMessage() { 
     return this.message; 
    } 
} 

bootstrap.yml of config-client 
spring: 
    application: 
    name: config-client 
    cloud: 
    config: 
     uri: http://localhost:8888 
management: 
    security: 
    enabled: false 


application.yml of config-server 
spring: 
    application: 
    name: config-server 
    cloud: 
    config: 
     server: 
     git: 
      uri: https://github.com/config-properties 
server: 
    port: 8888 

日誌

開始ApplicationContext的錯誤。要顯示自動配置報告,請啓用'debug'重新運行您的應用程序。 2017年8月18日23:13:45.080錯誤13812 --- [主] osboot.SpringApplication:應用程序啓動失敗

org.springframework.beans.factory.BeanCreationException:錯誤名爲「創造豆scopedTarget.restController ':注入自動裝載的依賴關係失敗;嵌套異常是java.lang.IllegalArgumentException:無法解析org.springframework.beans.factory.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)〜[spring-type]中的值「$ {message}」 中的佔位符'message' beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)〜[spring-beans-4.3.10.RELEASE。 jar:4.3.10.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)〜[spring-beans-4.3.10.RELEASE .jar:4.3.10.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory $ 2.getObject(AbstractBeanFactory.java:345)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10。發佈] at org.springframework.cloud.context.scope.GenericScope $ BeanLifecycleWrapper.getBean(GenericScope.java:359)〜[spring-cloud-context-1.2.3.RELEASE.jar:1.2.3.RELEASE] at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:176)〜[spring-cloud-context-1.2.3.RELEASE.jar:1.2.3.RELEASE] at org.springframework.beans。 factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean( AbstractBeanFactory.java:197)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.spring framework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.cloud.context.scope.refresh。 RefreshScope.start(RefreshScope.java:121)〜[spring-cloud-context-1.2.3.RELEASE.jar:1.2.3.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8 .0_144] 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[NA:1.8.0_144] 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[NA:1.8.0_144 ] at java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_144] at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:256)〜[spring -context-4.3.10.RELEASE .jar:4.3.10.RELEASE] at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster .invokeListener(SimpleApplicationEventMulticaster.java:167)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster。java:139)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)〜[spring-context- 4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)〜[spring-context-4.3.10.RELEASE.jar:4.3。 10.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework。 boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)〜[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh( AbstractApplicatio nContext.java:546)〜[彈簧上下文4.3.10.RELEASE.jar:4.3.10.RELEASE] 在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)〜[ spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)[spring-boot-1.5.6.RELEASE.jar:1.5 .6.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at org.springframework.boot。 SpringApplication.run(SpringApplication.java:303)[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)[spring- boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at org.springframework.boot.SpringApplication.run (SpringApplication.java:1107)[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] at com.demo.ConfigClientApplication.main(ConfigClientApplication.java:9)[classes /:na] 引起通過:java.lang.IllegalArgumentException:無法解析值爲「$ {消息}」 位於org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)〜[spring-core-4.3.10 .RELEASE.jar:4.3.10.RELEASE] at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)〜[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE] 在org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236)〜[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.core.env.AbstractPropertyResol ver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210)〜[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.support.PropertySourcesPlaceholderConfigurer $ 2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172 )〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:831)〜[spring-beans-4.3 .10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086)〜[spring-beans-4.3.10.RELEASE.jar:4.3 .10.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans .factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues (AutowiredAnnotationBeanPostProcessor.java:366)〜[彈簧豆-4.3.10.RELEASE.jar:4.3.10.RELEASE] ... 31個共同幀省略

斷開從目標VM,地址:「127.0。 0。1:59908',transport:'socket'

+0

https://github.com/config-properties看起來並不像一個有效的資料庫。 – spencergibb

+0

對不起忘了提,其有效,但已刪除完整路徑。該文件的內容與彈簧指南相同。 – Sandhya

+0

什麼來自日誌? – spencergibb

回答

0

確保GIT URI有效,應該是https://github.com/userName/repositoryName 然後將配置文件夾推送到repositoryName。

例子:https://github.com/PraveenKumarMekala/Microservices-With-Spring-Example

這裏我有文件夾,名爲ConfigData,我把我所有的陽明files.Same方式,你也應該有配置-client.yml文件(YML文件名一個文件夾應該是相同的應用程序名,因爲你沒有提到在您的客戶端文件陽明海運任何配置文件,以便它會退回到您的默認配置文件與應用程序的名稱)

你YML文件應該如下

配置,client.yml --- message : Hello World!

config-client.yml文件應該放在你的git倉庫中。

bootstrap.yml配置客戶端的

--- spring: profiles: active: profileName application: name: config-client cloud: config: uri: http://localhost:8887 server: port: 8888

注:如果您提及PROFILENAME然後陽明的文件名應該是配置,客戶profileName.yml

application.yml的配置服務器

--- spring: cloud: config: server: git: uri:https://github.com/PraveenKumarMekala/Microservices-With-Spring-Example searchPaths: ConfigData # "native" is used when the native profile is active, for local tests with a classpath repo: native: searchLocations: classpath:offline-repository/ server: port: 8888

做這個改變和嘗試,希望它是有用的。

PS:如果你沒有git的賬號,創建一個帳戶,然後倉庫

https://help.github.com/articles/create-a-repo/

相關問題