Spring-Cloud配置服务器忽略配置属性文件 [英] Spring-Cloud configuration server ignores configuration properties file

查看:795
本文介绍了Spring-Cloud配置服务器忽略配置属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a Spring Cloud configuration server which reads the configuration data from the properties file and not a github. The server starts, but does not serve the properties from the file. I have two configuration files on the classpapath:

bootstrap.yml

bootstrap.yml

spring:
application:
    name: config-server

config-server .properties

config-server.properties

foo=bar

当我转到应该给我foo属性值的url时:

when I go to the url which supposedly should give me the value of the foo property:

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,路径:/ admin / env / foo}

I get an error: "timestamp":1415298615005,"status":404,"error":"Not Found","exception":"org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint$NoSuchPropertyException","message":"No such property: foo","path":"/admin/env/foo"}

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

I am wondering what I am doing wrong? As far as I understand the properties file name should match the server name in order to be recognized by the server.

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

adding native profile as spencergibb suggested did not help. my application.properties looks like:

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

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

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

The POM file has no parent and a single dependency:

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

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

The application has nothing special in it:

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

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

The configserver.properties file contains a single entry: foo=bar

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

First of all I am always getting a startup error

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

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

Regardless of which command I execute I am always getting the same response from the server:

{"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 将配置文件设置为 native ,以便配置服务器提供服务春天的环境。配置服务器的 spring.config.name 以编程方式设置为 spring.config.name = configserver ,以便您的属性文件需要是configserver.properties。

By default, the config server serves properties from git. You will need to set the profile to native using --spring.profiles.active=native for the configserver to serve the spring environment. The spring.config.name for the config server is programmatically set to spring.config.name=configserver so your properties file will need to be configserver.properties.

这篇关于Spring-Cloud配置服务器忽略配置属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆