I am trying to build a sample app on Spring boot and spring cloud. I have written my database and hibernate configuration in config.properties property file which is located in my desktop and I want my spring boot to make use of this configuration.
My project have 3 modules
This is the code that I have mentioned in the application.property file of API
spring.profiles.active=native spring.cloud.config.server.native.searchLocation=C:/Users/DEV/Desktop/configuration/config.properties
and the property file of DataLayer and ServiceLayer is empty
But when I run the API I am getting the following error
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
Could any one help me with this error.
Thanks in advance.
This is can not be done from your API module. You added configuration server properties to your 'client' (from configuration point of view) application.
If you want to use Spring Cloud Config to configure your project you should have separate application that will manage your configuration. Let's call it config-server
. (You should properly configure maven or gradle dependencies, see documentation) To configure usage of native
profile in the config-server
in application.properties
you have to add properties that you mentioned in the question (example for native
profile).
spring.profiles.active=native
spring.cloud.config.server.native.searchLocation=file:<path-to-the-directory-with-conf-files> or classpath:/<path-to-the-directory-with-conf-files>
Note: config-server
can handle configuration for lot of services.
More can be found in the documentation Spring Cloud Config Server section.
Then in your API (or any other module) which is a spring boot app you should add spring-cloud-config-client
dependency and add bootstrap.properties
(or .yml) configuration file. There your should add properties that will describe communication with config-server
. By default config-server
listens on port 8888.
spring.application.name=<your app name>
spring.cloud.config.uri=http://localhost:8888 # this is also default value for this property
At start-up it will go by http to config-server
and fetch your configuration properties based on service name (spring.application.name
).
More can be found in Spring Cloud Config client section
Important: make sure your properly organize files in your configuration directory (which is used by native
profile by config-server
), find some samples. Property files naming are important. For start you can try to use your-application-name.properties