发生“Failed to configure a DataSource“问题的一种原因及解决办法

项目架构:springcloud + nacos + gitlab ci/cd

问题描述:在跑一个springcloud项目的时候,本地运行完全正常,而通过gitlab ci/cd部署至服务器时,发生如下错误,其原因是找不到数据库连接配置。

2022-10-17 14:28:38.943 ERROR 1 --- [           main] 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 (the profiles develop are currently active)

在经过一天各种Google与尝试后,依然没找到问题所在,最后在我司架构师帮助下,十分钟解决了,问题出在spring.profiles.active配置上。

本地bootstrap.yml部分配置如下

# Spring
spring: 
  profiles:
    # 环境配置
    active: rk_develop
  cloud:
    nacos:
      discovery:
        # 服务注册地址
        server-addr: [已隐藏]
        namespace: ${spring.profiles.active}

运维在部署的时候,执行了以下脚本,给了一个"spring.profiles.active=${CI_BUILD_REF_NAME}“的启动入参,而”${CI_BUILD_REF_NAME}“的值为"develop”,覆盖了本地bootstrap.yml中的相应配置,导致nacos找错了命名空间。后与运维联系去掉此入参后,项目得以正常启动。

ENTRYPOINT ["java", "-XX:+UseG1GC", "-Xms512m", "-Xmx512m", "-server", "-Djava.security.egd=file:/dev/./urandom", \
     "-jar", "rk.jar", "-spring.config.location=/bootstrap.yml", \
    "--spring.profiles.active=${CI_BUILD_REF_NAME}"]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值