我正在尝试创建一个Spring配置服务器,它从属性文件而不是github读取配置数据。服务器启动,但不提供文件中的属性。我在类路径上有两个配置文件:
bootstrap.yml
spring:
application:
name: config-serverconfig-server.properties
foo=bar当我到url时,它应该给我foo财产的价值:
curl http://localhost:8888/admin/env/foo我得到了一个错误:“时间戳”:1415298615005,“状态”:404,“错误”:“未找到”,"exception":"org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint$NoSuchPropertyException",“消息”:“无此属性: foo",”路径“:”/admin/env/foo“}
我想知道我做错了什么?据我所知,为了被服务器识别,属性文件名应该与服务器名称相匹配。
按照spencergibb的建议,添加本机配置文件没有帮助。我的application.properties看起来像:
server.port=8888
spring.profiles.active=native
spring.config.name=configserver
spring.application.name=configserver注意到,我必须指定服务器端口。根据文档,默认情况下,配置服务器在端口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文件包含一个条目: 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无论我执行哪个命令,我总是从服务器获得相同的响应:
{"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响应总是如上所示
发布于 2014-11-06 19:13:10
默认情况下,配置服务器提供来自git的属性。您需要使用native将配置文件设置为--spring.profiles.active=native,以便为spring环境服务。配置服务器的spring.config.name以编程方式设置为spring.config.name=configserver,因此您的属性文件需要是configserver.properties。
发布于 2014-11-07 08:11:23
配置服务器中的"/admin/env“端点只提供服务器本身的本地配置。服务器通常只是一个普通的Spring应用程序,所以它从"application.properties“获得它的配置。如果您想从"config-server.properties“中获取它,则需要设置"spring.config.name”或"spring.config.location“(就像普通的引导应用程序)。
https://stackoverflow.com/questions/26786865
复制相似问题