Reputation: 273
I'm trying to set up Spring Cloud Config Server with backend repository (filesystem), but the endpoint(http://localhost:8888/licensingservice/default
) returns the following:
{"name":"licensingservice","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[]}
The Main:
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
The application.yml:
server:
port: 8888
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: file:///Users/josedavi/Desenvolvimento/WorkSpace/Pessoal/sample-spring-microservices/sample-spring-microservices/config-server/src/main/resources/config
The licensingservice.yml:
tracer.property: "I AM THE DEFAULT"
spring.jpa.database: "POSTGRESQL"
spring.datasource.platform: "postgres"
spring.jpa.show-sql: "true"
spring.database.driverClassName: "org.postgresql.Driver"
spring.datasource.url: "jdbc:postgresql://database:5432/eagle_eye_local"
spring.datasource.username: "postgres"
spring.datasource.password: "p0stgr@s"
spring.datasource.testWhileIdle: "true"
spring.datasource.validationQuery: "SELECT 1"
spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"
The path of the service config:
C:\Users\josedavi\Desenvolvimento\WorkSpace\Pessoal\sample-spring-microservices\sample-spring-microservices\config-server\src\main\resources\config
The Project: https://github.com/jdavid-araujo/sample-spring-microservices
Upvotes: 8
Views: 26800
Reputation: 703
1-
set uri in property (yml) file as below :
uri: file:///C:/properties/application.yml
spring:
application:
name: Config-Service
cloud:
config:
server:
git:
# uri: https://github.com/xxxx/config-server/
uri: file:///C:/properties/application.yml
clone-on-start: true
2-
another way is to create a git directory in folder that yml file is exist:
then set config as follows :
spring:
application:
name: Config-Service
cloud:
config:
server:
git:
uri: file:///C:/properties/
clone-on-start: true
Upvotes: 2
Reputation: 3373
spring:
cloud:
config:
server:
native:
search-locations:
- classpath:/config # Config files for all microservices
- classpath:/config/{application} # Config files for specific applications
I suggest you don't use absolute paths because it won't work unless it is running on your machine. Better use a relative path to your classpath so that you can also deploy your config server somewhere.
native
profileThe documentation does not explicitely state that the profile is needed, but for me it only worked with multiple search-locations
when I used the native
profile.
Upvotes: 0
Reputation: 1
config server folder structure
Then in application.yaml file cloud: config: server: native: search-locations: "[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]"
It will work perfectly
Upvotes: 0
Reputation: 5968
Add the following format in your application.yml
of config service:
[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]
The above format search locations from config
folder, next folder with application
name, application
name and profile
respectively.
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: "[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]"
Upvotes: 7
Reputation: 3878
It seems that the problem is your searchLocations
property. The path must reach the licensingservice
folder itself, and if the server provides configuration for more than one service, you must set the paths for each of them (separated by comma).
Try this way:
...
spring:
...
cloud:
config:
server:
native:
searchLocations: file:///C:/Users/josedavi/Desenvolvimento/WorkSpace/Pessoal/sample-spring-microservices/sample-spring-microservices/config-server/src/main/resources/config/licensingservice
Alternatively, you can use the relative path:
...
searchLocations: classpath:config/licensingservice
Also, if you are reading the Spring Microservices in Action book (Chapter 3), you can take a look at the source code example itself.
Upvotes: 3