springboot整合jdbc错误笔记

springboot整合mybatis&jdbc报错

新手小白初始建立一个简单的spring boot项目整合jdbc和mybatis后的调试出现几个错误。接下来以个人笔记的形式总结报错。

1、关于datasource的bean装载问题

报错如下所示:

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcDao': Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration': 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

这里的问题在于我的Datasource这里并没有配置好,那么自然而然就要想到这里的问题。

即设置datasource。

2、关于url no set问题

这里如果使用DruidDataSource数据库包要记得看清楚util包下的属性名是jdbcUrl,在配置dataSource很容易出现url no set的错误,所以这里我是手动输入更加保险。以下就是出现url路径发生的报错:

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: url not set

我这里可以通过手动设置datasource来完成。

@Bean
    @ConfigurationProperties(prefix = "jdbc")
    public DataSource dataSource() {
        DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName("com.mysql.cj.jdbc.Driver");
        dataSourceBuilder.url("jdbc:mysql://localhost:3306/user?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8");
        dataSourceBuilder.username("root");
        dataSourceBuilder.password("root");
        return dataSourceBuilder.build();
    }

最后完成后截图所示:

在这里插入图片描述
以上暂时是我目前遇到的问题,以此作为记录谢谢大家阅读和指正。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
您可以在 Docker 中使用以下命令检查 ShardingProxy 是否已经启动: 1. 查看 Docker 容器列表,找到正在运行的 ShardingProxy 容器的 ID: ``` docker ps ``` 2. 进入 ShardingProxy 容器的命令行: ``` docker exec -it 容器ID /bin/bash ``` 3. 查看 ShardingProxy 启动日志: ``` tail -f /opt/sharding-proxy/logs/stdout.log ``` 如果 ShardingProxy 启动成功,您应该能够看到类似以下的日志信息: ``` 2019-04-09 09:57:28.696 INFO main o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 0 before other processors start 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'configurationPropertiesRebinder' of type [class org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'refreshScope' of type [class org.springframework.cloud.context.scope.refresh.RefreshScope] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.boot.autoconfigure.AutoConfigurationPackages' of type [class org.springframework.boot.autoconfigure.AutoConfigurationPackages] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.context.properties.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.context.properties.ConfigurationPropertiesRebinderAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ReloadConfigurationProperties' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ReloadConfigurationProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ConfigurationPropertiesBeans' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ConfigurationPropertiesBeans] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ConfigurationPropertiesRebinderConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ConfigurationPropertiesRebinderConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.704 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$InjectedConfigurationPropertiesRebinder' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$InjectedConfigurationPropertiesRebinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.705 INFO main org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ConfigurationPropertiesRebinderMessageHandlerAdapter' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ConfigurationPropertiesRebinderMessageHandlerAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-04-09 09:57:28.705 INFO main o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147483647 2019-04-09 09:57:28.705 INFO main c.a.s.s.p.ShardingPropertiesLoader - Sharding-Proxy configuration is loaded from /opt/sharding-proxy/conf/config-sharding.yaml 2019-04-09 09:57:28.712 INFO main c.a.s.s.p.ShardingPropertiesLoader - Server lists configuration is loaded from /opt/sharding-proxy/conf/server.yaml 2019-04-09 09:57:28.713 INFO main o.a.s.proxy.frontend.netty.NettyFrontendEngine - Proxy context init, listen on [127.0.0.1:3307], pid is [1] and group is [default] 2019-04-09 09:57:28.713 INFO main o.a.s.proxy.frontend.netty.NettyFrontendEngine - Register Netty channel to Synchronizer success. 2019-04-09 09:57:28.713 INFO main o.a.s.p.s.SchemaChangedNotifier - === Sharding-Proxy start success === ``` 如果没有发现类似的日志信息,那么可能是 ShardingProxy 启动失败,请查看日志文件以确定失败原因。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Xiao艾扶

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

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

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

打赏作者

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

抵扣说明:

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

余额充值