spring boot 连接SQL SERVER 部署k8s docker环境后报错:Failed to configure a DataSource: ‘url‘ attribute is not

博客讲述了作者在将Spring Boot应用部署到Docker及Kubernetes环境后,遇到数据库连接DataSource配置问题。经过排查,发现并非JDBC驱动问题,而是应用未能正确读取环境特定的配置文件(如`application-prd2.yml`)。解决方案是确保Docker环境中应用使用`application.properties`文件进行配置,从而成功解决问题。

本机调试OK,但是部署DOCKER之后报错:

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

 

一直以为是数据驱动JAR问题,后来验证了两点:

 

1:spring boot 2.0之后,数据库连接SQL server用:

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>

2:如果有外部JAR打包需要配置:

2.1:拷贝JAR到src-resources-lib文件夹下

2.2:补充POM.XML下配置

        <dependency>
            <groupId>com</groupId><!--随便填的-->
            <artifactId>xcwebapi</artifactId><!--jar包名字-->
            <version>1.1</version><!--版本号-->
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/JDK_1.8_corp.openapicalls.lib.webapi.jar</systemPath><!--路径-->
        </dependency>

2.3:补充加载所有JAR

<build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/resources/lib/</directory>
                            <targetPath>WEB-INF/lib/</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

这两点验证没问题之后,部署K8 DOCKER还是报错。

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. (ConditionEvaluationReportLoggingListener.java:136) 
[2020-07-29 01:21:28,697][ERROR][main] 
 
*************************** 
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). 
 (LoggingFailureAnalysisReporter.java:40) 
[2020-07-29 01:21:28,700][ERROR][main] ERR-运行发生错误:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; 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 (XiechengApplication.java:30) 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'data
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫气东来_999

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值