我试图在Spring客户端与Spring配置服务器之间共享配置,Spring配置服务器有一个基于文件的存储库:
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
// application.yml
server:
port: 8888
spring:
profiles:
active: native
test:
foo: world我的Spring客户机之一使用配置服务器中定义的test.foo配置,配置如下:
@SpringBootApplication
@RestController
public class HelloWorldServiceApplication {
@Value("${test.foo}")
private String foo;
@RequestMapping(path = "/", method = RequestMethod.GET)
@ResponseBody
public String helloWorld() {
return "Hello " + this.foo;
}
public static void main(String[] args) {
SpringApplication.run(HelloWorldServiceApplication.class, args);
}
}
// boostrap.yml
spring:
cloud:
config:
uri: ${SPRING_CONFIG_URI:http://localhost:8888}
fail-fast: true
// application.yml
spring:
application:
name: hello-world-service尽管有这种配置,Spring客户机中的Environment不包含test.foo条目(cf java.lang.IllegalArgumentException: Could not resolve placeholder 'test.foo')
但是,如果我将这些属性放在基于配置服务器文件的存储库中的hello-world-service.yml文件中,那么它就能很好地工作。
Maven对Spring Brixton.M5和SpringBoot1.3.3的依赖关系。3.使用
spring-cloud-starter-config和spring-cloud-config-server的Brixton.M5
发布于 2016-03-02 16:09:53
来自弹簧云文档
对于“本机”配置文件(本地文件系统后端),建议您使用不属于服务器自身配置的显式搜索位置。否则,默认搜索位置中的应用程序*资源将被删除,因为它们是服务器的一部分。
因此,我应该将共享配置放在外部目录中,并将路径添加到config-server的config-server文件中。
// application.yml
spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: file:/Users/herau/config-repo
// /Users/herau/config-repo/application.yml
test:
foo: worldhttps://stackoverflow.com/questions/35749567
复制相似问题