Spring-Cloud配置服务器忽略配置属性文件

我正在尝试创建一个Spring Cloud配置服务器,它从属性文件而不是github读取配置数据。 服务器启动,但不提供文件中的属性。 我在classpapath上有两个配置文件:

bootstrap.yml

spring: application: name: config-server 

config-server.properties

 foo=bar 

当我去url,据说应该给我foo属性的值:

 curl http://localhost:8888/admin/env/foo 

我收到一个错误:“timestamp”:1415298615005,“status”:404,“error”:“Not Found”,“exception”:“org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint $ NoSuchPropertyException”,“message “:”没有这样的属性:foo“,”path“:”/ admin / env / foo“}

我想知道我做错了什么? 据我所知,属性文件名应与服务器名称匹配,以便服务器识别。


添加原生配置文件作为spencergibb建议没有帮助。 我的application.properties看起来像:

 server.port=8888 spring.profiles.active=native spring.config.name=configserver spring.application.name=configserver 

注意,我必须指定服务器端口。 根据Spring Cloud Config Server文档,配置服务器默认在端口8888上启动。 在我的情况下,除非我在配置中指定端口,否则服务器从8080开始。

POM文件没有父级和单个依赖项:

    org.springframework.cloud spring-cloud-config-server 1.0.0.M2   

该应用程序没有什么特别之处:

 @Configuration @ComponentScan @EnableAutoConfiguration @EnableConfigServer public class ConfigurationApp { public static void main(String[] args) { SpringApplication.run(ConfigurationApp.class, args); } } 

configserver.properties文件包含一个条目:foo = bar

首先,我总是遇到启动错误

 2014-11-07 09:35:42.852 ERROR 6972 --- [ main] bcPropertySourceBootstrapConfiguration : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/configserver/default/master":Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect 

无论我执行哪个命令,我总是从服务器获得相同的响应:

 {"name":"info","label":"master","propertySources":[{"name":"bootstrap","source":{}},{"name":"applicationConfig: [classpath:/application.properties]","source":{"spring.config.name":"configserver","spring.application.name":"configserver","server.port":"8888","spring.profiles.active":"native"}},{"name":"defaultProperties","source":{"spring.application.name":"bootstrap"}}]} 

我试过了:

 http://localhost:8888/configserver/env http://localhost:8888/configserver/env/foo http://localhost:8888/configserver/info http://localhost:8888/configserver/beans http://localhost:8888/configserver/health 

响应总是如上所述

默认情况下,配置服务器从git提供属性。 您需要使用--spring.profiles.active=native将配置文件设置为--spring.profiles.active=native ,以便为spring服务器提供服务。 配置服务器的spring.config.name以编程方式设置为spring.config.name=configserver因此您的属性文件需要是configserver.properties。

配置服务器中的“/ admin / env”端点仅服务于服务器本身的本地配置。 服务器通常只是一个常规的Spring Boot应用程序,因此它从“application.properties”获取其配置。 如果你想从“config-server.properties”中选择它,你需要设置“spring.config.name”或“spring.config.location”(就像普通的Boot应用程序一样)。