我所有的代码都在这里https://github.com/spencergibb/communityanswers/tree/so27131143
src/main/java/Application.java
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
src/main/resources/application.yml
spring:
application:
name: myconfigserver
profiles:
active: native
my:
property: myvalue
src/main/resources/myapp.yml
my:
otherprop: myotherval
要获取名为 的应用程序的属性myapp
,请执行以下操作。
curl http://localhost:8080/myapp/default
{
"name": "default",
"label": "master",
"propertySources": [
{
"name": "applicationConfig: [classpath:/myapp.yml]",
"source": {
"my.otherprop": "myotherval"
}
},
{
"name": "applicationConfig: [classpath:/application.yml]",
"source": {
"spring.application.name": "myconfigserver",
"spring.profiles.active": "native",
"my.property": "myvalue"
}
}
]
}