2014-11-06 145 views
6

我试图创建一个Spring Cloud配置服务器,它从属性文件中读取配置数据而不是github。服务器启动,但不提供文件中的属性。我对classpapath两个配置文件:Spring-Cloud配置服务器忽略配置属性文件

bootstrap.yml

spring: 
application: 
    name: config-server 

config-server.properties

foo=bar 

当我去据称应该给我的值的URL foo楼盘:

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

我得到一个错误: “时间戳“:1415298615005,”status“:404,”error“:”Not Found“,”exception“:”org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint $ NoSuchPropertyException“,”message“:”No such property :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文件没有父母和一个单一的依赖性:

<dependencies> 
    <dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-config-server</artifactId> 
     <version>1.0.0.M2</version> 
    </dependency> 
</dependencies> 

应用程序有没有什么特别的吧:

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

的configserver.properties文件包含一个条目:富=酒吧

首先我总是得到一个启动错误

2014-11-07 09:35:42.852 ERROR 6972 --- [   main] b.c.PropertySourceBootstrapConfiguration : 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 

的响应总是如上

回答

5

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

+0

我将您建议的设置添加到application.properties。错误消失了,但我仍然无法获得我的物业。我更新了我的原始帖子,更多信息 – MrkK 2014-11-07 15:14:53

+0

在此处查看我的答案:http://stackoverflow.com/a/27159030/2730527 – spencergibb 2014-11-26 21:18:59

1

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