java - 配置服务器无法配置数据源 : 'url' attribute is not specified and no embedded datasource could be configured

标签 java spring-boot spring-cloud-config application.properties

我正在尝试从包含所有应用程序属性的 github 存储库中获取数据库配置。下图说明了我拥有的服务的结构:

enter image description here

当我访问我的配置服务器微服务时,一切正常,即使我在 postman 中测试它时,我也会恢复配置。

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

这些是我拥有的所有属性文件:

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

产品服务应用程序.properties
## Server Properties
server.port= 7000

配置服务器 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

github 上的产品服务应用程序.properties
#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

最佳答案

问题出在配置服务器客户端的 porm 文件中,您需要添加 Spring Cloud starter Config 依赖项。在您的产品微服务中添加以下依赖项。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>

关于java - 配置服务器无法配置数据源 : 'url' attribute is not specified and no embedded datasource could be configured,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53353138/

相关文章:

Java - 播放/暂停 VLC

java - spring-rabbitmq 自动重试连接到代理

java - spring-boot-starter-integration 1.4.3 性能下降

java - Javers 将字段与注释进行比较

java - Bootstrap.properties中Spring.application.name的意义

java - 无法从Spring云配置服务器中的GIT读取属性源

Spring Cloud Config 和 Spring Cloud Vault 的初始化顺序

java - 如何在hibernate环境中查询RevisionEntity

java - 使用 Java 导入 SQL

java - 如何通过正则表达式找到特殊模式