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

Mrk*_*rkK 6 java spring-cloud

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

bootstrap.yml

spring:
application:
    name: config-server
Run Code Online (Sandbox Code Playgroud)

config-server.properties

foo=bar
Run Code Online (Sandbox Code Playgroud)

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

curl  http://localhost:8888/admin/env/foo
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:"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
Run Code Online (Sandbox Code Playgroud)

注意,我必须指定服务器端口.根据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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

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
Run Code Online (Sandbox Code Playgroud)

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

{"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"}}]}
Run Code Online (Sandbox Code Playgroud)

我试过了:

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
Run Code Online (Sandbox Code Playgroud)

响应总是如上所述

spe*_*ibb 5

默认情况下,配置服务器从git提供属性.您需要将配置文件设置为native使用--spring.profiles.active=nativeconfigserver来为spring环境提供服务.在spring.config.name为配置服务器编程设置为spring.config.name=configserver使您的属性文件将需要configserver.properties.