AI智能
改变未来

UnsatisfiedDependencyException and Failed to configure a DataSource


问题描述

未使用数据库操作时,尝试项目启动,检测环境配置时,却报了一个错误
错误描述:未指定“url”属性,无法配置嵌入的数据源。

详细提示信息:

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

原因

经检测发现,虽然没有使用数据库操作,但却导入了jdbc的依赖以及Druid的依赖

另一个注意

经过实验,导致该问题的原因时spring-boot-starter-jdbc这个启动器。
但Druid启动器也需要删除,否则回报名为UnsatisfiedDependencyException的异常。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name \'dataSource\': Unsatisfied dependency expressed through field \'basicProperties\'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name \'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties\': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType

总结

在未使用到之前尽量不导入不需要的启动器。
避免出错的同时,也能避免pom.xml文件的臃肿。

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » UnsatisfiedDependencyException and Failed to configure a DataSource