Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/roncoo/spring/boot/autoconfigure/druid/DruidAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.druid.pool.DruidDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: java.sql.SQLException: url not set
错误原因,真的找不到哪里错误了。
网上查到的方法都试过了,是下载的一个开源项目,别的都能运行就这个报:url not set。
这个方法试过了 @Bean 不能加@ConfigurationProperties(prefix = "spring.datasource"), 这个类不能被修改是仅可读的。
这个方法也是试过的,行不通
配置文件源码:@Bean @ConfigurationProperties(prefix = "spring.datasource.hikari")
我写的application.proties: spring.datasource.hikari.jdbc-url=
贴出代码或配置文件
【chatgpt解决方法】:
这是一个Spring Boot项目中的错误,与Druid数据源有关。它提示您没有设置数据库的URL,导致数据源实例化失败。
1、确保在application.properties或application.yml中设置了数据库的URL,例如:spring.datasource.url=jdbc:mysql://localhost:3306/test
2、确保数据库正在运行并可以连接。
3、确保已在您的项目中正确导入Druid数据源和MySQL JDBC驱动程序。
sql异常,是不是可以查查,你报错的那个能不能用浏览器访问。
在你的要用的bean
@Bean上面加上这个试试:
@ConfigurationProperties(prefix = “spring.datasource”)
最后一句说了, java.sql.SQLException: url not set url没有设置
检查配置文件有没有配置url,durid读取的类里面的url名称和配置文件里面的名称 要一致
数据库连接池url配置问题,检查配置文件。如果搞不定,那就自己换一个连接池用呗,反正都是连接数据库的工具,用谁的都一样。