2016-05-06 28 views
3

我有一个弹簧云问题:执行应用程序时,我没有使用application.yml中的设置,因为spring.cloud.config 。让我在这里提供更多细节。 我想我的服务可以从远程ConfigServer获取设置。我已将ConfigServer创建为带有注释@EnableConfigServer的Spring Boot应用程序。 后,我已经创建了下一个配置文件,客户端应用程序:执行应用程序时,不会使用application.yml中的设置执行应用程序

application: 
     name: mw 
    cloud: 
     config: 
     enabled: true 
     uri: http://172.17.42.1:8888 
     fail-fast: true 

主类:

@EnableEurekaClient 
    @SpringBootApplication 
    public class MwApplication 

和额外的配置到应用程序:

@Configuration 
    @EnableJpaRepositories(basePackages = {"com.sample.repository"}) 
    @EnableTransactionManagement 
    @EnableScheduling 
    public class AppConfiguration 

还我旁边的依赖关系:

spring-cloud-starter-eureka 
    spring-cloud-config-client 
    spring-boot-configuration-processor 
    spring-boot-starter-data-jpa 

当我执行我的客户端应用程序,因为我得到了这样的信息:ConfigServicePropertySourceLocator:找不到PropertySource:对GET请求“http://localhost:8888/mw/default

的应用程序试图从默认的URI(本地主机)的数据I/O错误,而不是从我的设置中使用uri。我已经在调试模式下看过app,看到org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration创建了ConfigClientProperties和默认属性,我的application.yml设置没有被使用。

我在做什么错了? 谢谢。

回答

3

您需要添加以下到您的application.yml文件:

spring: 
    cloud: 
     config: 
      enabled: true 

根据注释链,你还需要添加的属性bootstrap.yml而不是application.yml。原因是前者在春季启动周期之前加载后者。这里是另一个SO后由用户Michael Isvy解释为什么回答,以下为复制的后人:What is the diference between putting a property on application.yml or bootstrap.yml in spring boot?

我刚才问Spring Cloud家伙,我想我应该分享信息,我这里有。

bootstrap.yml在application.yml之前加载。

它通常用于以下:

    使用Spring云配置服务器时
  • ,应指定spring.application.namespring.cloud.config.server.git.uribootstrap.yml
  • 一些encryption/decryption信息

技术上,bootstrap.yml是由父级Spring ApplicationContext加载。该父ApplicationContext在使用application.yml之前加载。

+0

我已经尝试过了,再次添加,但没有改变的,我还是有这个问题 – slippery

+1

尝试移动application.yml配置bootstrap.yml – Andonaeus

+0

现在的作品,谢谢!你能说出为什么它不适用于应用程序。阳明海运? 我没有自己创建application.yml。它是由spring构造函数 – slippery