问题描述
我一直在玩github上的Spring Cloud项目:
I have been playing around with the Spring Cloud project on github located here: https://github.com/spring-cloud/spring-cloud-config
但是我遇到了一些问题,让它读取本地属性文件而不是从github拉出属性。即使我删除了对github的所有引用,spring似乎也忽略了本地文件。此处发布了类似的问题:
However I have been running into some problems getting it to read a local properties file instead of pulling the properties from github. It seems that spring is ignoring the local file even when I remove all the references to github. There is a similar question posted here: Spring-Cloud configuration server ignores configuration properties file
但我还没有看到任何好的答案。我想知道是否有人能指出我的一个例子?我想在本地设置我的属性,而不是使用任何类型的git repo。我假设有人之前遇到过这种情况,如果有某个例子,我真的很想看到它,这样我才能朝着正确的方向前进。
But I haven't seen any good answers yet. I'm wondering if anyone can point me to an example of this? I'd like to set my properties locally instead of using a git repo of any kind. I assume someone has encountered this before, and if there is an example of it somewhere, I'd really like to see it so that I can get moving in the right direction.
推荐答案
我的所有代码都在这里
All my code is here https://github.com/spencergibb/communityanswers/tree/so27131143
src / main / java / Application.java
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
src/main/resources/application.yml
spring:
application:
name: myconfigserver
profiles:
active: native
my:
property: myvalue
src / main / resources / myapp.yml
src/main/resources/myapp.yml
my:
otherprop: myotherval
要获取名为 myapp
的应用的属性,请执行以下操作。
To get the properties for an app named myapp
, do the following.
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"
}
}
]
}
这篇关于Spring Cloud Configuration Server无法使用本地属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!