Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Config-Server Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

I am trying to get database configurations from a github repository that contains all application properties. The diagram below illustrates the structure of the service which i have:

enter image description here

When i access my config server microservice everything works fine and even when i test it in post man i get the configurations back.

The problem comes when i try to run the product service whilst pointing to the config server microservice to get database configurations. I get the error below:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.5.RELEASE)

2018-11-17 17:53:23.730  INFO 9497 --- [  restartedMain] o.a.s.p.ProductServicesApplication       : Starting ProductServicesApplication on users-MacBook-Pro.local with PID 9497 (/Users/user/Desktop/act/core-services/product-services/target/classes started by user in /Users/user/Desktop/act/core-services/product-services)
2018-11-17 17:53:23.732  INFO 9497 --- [  restartedMain] o.a.s.p.ProductServicesApplication       : No active profile set, falling back to default profiles: default
2018-11-17 17:53:23.773  INFO 9497 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@15d79dee: startup date [Sat Nov 17 17:53:23 SAST 2018]; root of context hierarchy
2018-11-17 17:53:25.307  INFO 9497 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$3317940b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-11-17 17:53:25.822  INFO 9497 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 7000 (http)
2018-11-17 17:53:25.844  INFO 9497 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-11-17 17:53:25.845  INFO 9497 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-11-17 17:53:25.854  INFO 9497 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/user/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-11-17 17:53:25.938  INFO 9497 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-11-17 17:53:25.938  INFO 9497 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2167 ms
2018-11-17 17:53:26.232 ERROR 9497 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$a1fbe591]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2018-11-17 17:53:26.253  INFO 9497 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-11-17 17:53:26.262  WARN 9497 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2018-11-17 17:53:26.275  INFO 9497 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-17 17:53:26.277 ERROR 9497 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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).

These are all the properties files i have:

Product-service bootstrap.properties

#Read file on Config-Server
#product-service.properties
spring.application.name=product-service
spring.cloud.config.uri=http://localhost:20001

Product-service application.properties

## Server Properties
server.port= 7000

config-server application.properties

spring.application.name=spring-cloud-config-server
server.port = 20001

#Config Server Connection
spring.cloud.config.server.git.uri=https://github.com/myrepository/link-config-files
spring.cloud.config.server.git.username = myaccount
spring.cloud.config.server.git.password = abcdef

Product-service application.properties on github

#Config Server Connection   

## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url= jdbc:postgresql://localhost:5432/mytestDB?useSSL=true
spring.datasource.username= postgres
spring.datasource.password= abxc***
spring.datasource.driver-class-name=org.postgresql.Driver


### Hibernate Properties
## The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.hibernate.ddl-auto = update

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

## Hibernate Logging
logging.level.org.hibernate.SQL= DEBUG

## Jackson Properties
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS= false
spring.jackson.time-zone= UTC

## App Properties
app.jwtSecret= JWTSuperSecretKey
app.jwtExpirationInMs = 604800000

## Spring Profiles
eureka.client.service-url.default-zone=http://localhost:8761/eureka
like image 844
Erent Avatar asked Mar 06 '23 01:03

Erent


1 Answers

The problem is in your porm file for the config server client, you need to add the Spring Cloud starter Config dependecy. Add the following dependency in your product microservice.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>
like image 195
DvixExtract Avatar answered Apr 28 '23 17:04

DvixExtract