0

I am trying to develop a microservice and deployment for two different regions. Two different region using two different database. So for using that, I created one spring cloud config server and defined database property for two different profiles,

Here Is my spring cloud config server project details, Created config folder in src/main/resources and add two files,

bootstrap-vcu.properties file containing,

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/milleTech_users
spring.datasource.username=postgres
spring.datasource.password=postgresql

bootstrap-sp.properties file containing,

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/espace
spring.datasource.username=postgres
spring.datasource.password=postgresql

Application.properties containing,

server.port=8888
spring.profiles.active=native 

Bootstrap.properties

spring.cloud.config.uri=localhost:8888

Folder structure for config server is as following,

enter image description here

And my pom.xml

<dependencies>
   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

And created separate project for spring cloud config client,

Config client project application.properties file is like,

server.port=8080
spring.cloud.config.uri=localhost:8888

And launching client application like ,

java -jar -Dsping.profiles.active=vcu ConfigClient-0.0.1-SNAPSHOT.war

But getting error as

"Failed to auto-configure a DataSource: 'spring.datasource.url' is not 
specified and no embedded datasource could be auto-configured"

Reason: Failed to determine a suitable driver class

Mr.DevEng
  • 2,651
  • 14
  • 57
  • 115

1 Answers1

1

Try to rename DbVcu.properties into application-DbVcu.properties and move it to src/main/ressources folder.

Sébastien Helbert
  • 2,185
  • 13
  • 22
  • Ok . Let me try sir. – Mr.DevEng Mar 21 '18 at 12:29
  • If it doesn't work, enable logging and look for loaded properties files to check if bootstrapping behave as you expect. – Sébastien Helbert Mar 21 '18 at 13:31
  • Its not working . I updated my question. Still only showing "spring.datasource.url". I didn't understood that logging enabling in your comment. – Mr.DevEng Mar 21 '18 at 14:30
  • In fact, given your configuration files I'm not sure that you understand how spring-cloud-config works and the distinction between the server and client part spring-cloud-config. Read this article that can clarify things : https://cloud.spring.io/spring-cloud-config/ – Sébastien Helbert Mar 21 '18 at 15:10
  • Yes, I found those link. I changing into bootstrap-vcu.properties / yml , Since spring cloud config server defining properties in bootstrap. And also it loaded before application.properties file loading. Now i have only one confusion that I documentation containing to add by git reference. "spring.cloud.config.server.git.uri". Here I don't want to give as git reference. I am preferring only property file (bootstrap-.yml/properties). Let me know if this approach is working for me. – Mr.DevEng Mar 21 '18 at 15:22
  • Hi Prince, again I think you misunderstood spring-cloud-config. First of all because the spring.cloud.config.uri property is ignored in application.properties. It must be in bootstrap.properties. Then, because the bootsrap file must be called bootstrap.properties (or .yml) not bootstrap-.yml / properties. Finally because I do not see any dependency on `spring-cloud-starter-config` nor `spring-cloud-config-client` in your pom, essential to download conf from the spring cloud server. Repeat the tutorial and if it works, add your code in it. – Sébastien Helbert Mar 22 '18 at 14:00
  • Yes , I updated with new addings. But still getting like ""Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured"". I updated my question. Can you please look on this? – Mr.DevEng Mar 23 '18 at 13:01
  • Reason is displaying as "Reason: Failed to determine a suitable driver class". – Mr.DevEng Mar 23 '18 at 13:08
  • yaa..That question is also mine. I explored and add result as answer. Now I am in right track. Thank you for your response and spending time with me Mr Sebastien Helbert – Mr.DevEng Mar 27 '18 at 08:42