her*_*rau 5 spring spring-boot spring-cloud
我正在尝试使用具有基于文件的存储库的Spring Cloud配置服务器在Spring Cloud客户端之间共享配置:
@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
Run Code Online (Sandbox Code Playgroud)
我的一个Spring Cloud客户端使用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
Run Code Online (Sandbox Code Playgroud)
尽管这种配置下,Environment在春天的云客户端不包含test.foo条目(CF java.lang.IllegalArgumentException: Could not resolve placeholder 'test.foo')
但是,如果我将属性放在一个hello-world-service.yml文件中,在我的基于配置服务器文件的存储库中,它的工作正常.
Maven依赖于Spring Cloud Brixton.M5和Spring Boot 1.3.3.RELEASE with
spring-cloud-starter-config和spring-cloud-config-server
\n\n\n对于“本机”配置文件(本地文件系统后端),建议您使用属于服务器自身配置的\xe2\x80\x99t 部分的显式搜索位置。否则,默认搜索位置中的应用程序资源将被删除,因为它们是服务器的一部分。
\n
所以我应该将共享配置放在外部目录中,并将路径添加application.yml到config-server.
// application.yml\nspring:\n profiles:\n active: native\n cloud:\n config:\n server:\n native:\n search-locations: file:/Users/herau/config-repo\n\n// /Users/herau/config-repo/application.yml\ntest:\n foo: world\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
914 次 |
| 最近记录: |