Spring Cloud Configuration Server not working with local properties file
Here is what I did:
following https://medium.com/@danismaz.furkan/spring-cloud-config-with-file-system-backend-c18ae16b7ad5
1) !!dont forget your VM options!!:
-Dspring.profiles.active=native
(in Netbeans : configserver->project->properties>Run->VM options
2) Either in application.properties
#spring.cloud.config.server.native.searchLocations=file:///C:/tmp/config
spring.cloud.config.server.native.searchLocations=classpath:/config
or applications.yml
spring:
cloud:
config:
server:
native:
search-locations : file:///C:/tmp/config
#search-locations : classpath:/config
Notes:
n1: search-locations and searchLocations both work
n2: file:/// => hard file path
Like
c:/temp/config/
app-admin.yml
app-admin-develop.yml
....
n3: for your profile config files
classpath:/
Like
Other sources/src/main/resources/config/app-admin.yml
n4: I couldnt made file paths work without setting the vm options. Dont forget! Just setting spring.profiles.active=native in your application config does not do the trick for me
n5: example http queries
http://localhost:8998/app-admin/default/yml
gives app-admin.yml
http://localhost:8998/app-admin/develop/yml
gives app-admin-develop.yml
All my code is here 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
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"
}
}
]
}
I am able to read configuration for apple-service(Test Micro Service) using Spring config server.
Example application.yml of spring config application
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: classpath:config/
server:
port: 8888
endpoints:
restart:
enabled: true
Put your .properties or .yml files inside src\main\resources\config folder. Make sure name of this files should match spring.application.name of your micro service.
For example if spring.application.name=apple-service then property file should be apple-service.properties in src\main\resources\config folder.
Example bootstrap.yml of apple-service:
spring:
application:
name: apple-service
cloud:
config:
uri: http://localhost:8888
Using spring.profiles.active=native is that what Spring documentation seems to suggest, but I couldn't get it to work either. My application.properties file is
server.port=8888
spring.cloud.config.profiles=native
but the response from the URL
http://localhost:8888/config-server/env
is
{"name":"env","label":"master","propertySources":[{"name":"https://github.com/spring-cloud-samples/config-repo/application.yml","source":{"info.url":"https://github.com/spring-cloud-samples","info.description":"Spring Cloud Samples"}}]}
which indicates that native profile was ignored and the server still considering github as property source.
A small additional problem I encountered is the config service default port. According to the Sprin Cloud Config documentation it should be 8888. If I remove server.port=8888 from my application.properties the config server starts on port 8080 which is default Spring Boot port, but not the one config server should use.