【踩坑记录】高级软件设计实作主题7druid配置问题的后续

项目场景

主题7-搭建基础工程-搭建商品系统微服务(160分钟)第12周


问题描述

上篇踩坑记录中更改完运行时还是会报错https://blog.youkuaiyun.com/q_645566340/article/details/124698424
1.java.lang.NullPointerException: null
2.Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the ‘serverTimezone’ configuration property) to use a more specifc time zone value if you want to utilize time zone support.


原因分析

1是空指针
2是没添加时区参数


解决方案

更改依赖包和配置文件

原来(接上篇踩坑记录)的druid依赖包

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

改成

        <!--阿里系的Druid依赖包-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.9</version>
        </dependency>
        <!-- Druid 依赖 log4j包 -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

相比老师文档中给的代码而言,配置文件改的比较多
原来(老师给的)

server.port=10001
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql:///easydb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=12345678
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.initialSize=5
spring.datasource.maxActive=50
spring.datasource.maxIdle=10
spring.datasource.minIdle=5

mybatis.typeAliasesPackage=com.easymall.common.pojo
mybatis.mapperLocations=classpath:mapper/*.xml
mybatis.configuration.mapUnderscoreToCamelCase=true
mybatis.configuration.cacheEnabled=false
spring.application.name=productservice
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

改成

server.port=10001
spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.druid.url=jdbc:mysql:///easydb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&serverTimezone=UTC
spring.datasource.druid.username=root
spring.datasource.druid.password=123456
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.initial-size=5
spring.datasource.druid.maxActive=50
#spring.datasource.druid.max-idle=10
spring.datasource.druid.min-idle=5

mybatis.typeAliasesPackage=com.drh.pojo
mybatis.mapperLocations=classpath:mapper/*.xml
mybatis.configuration.mapUnderscoreToCamelCase=true
mybatis.configuration.cacheEnabled=false
spring.application.name=productservice
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

PS:包路径和数据库密码记得改成自己对应的

改完再运行就不报错了,并且能成功访问http://localhost:10001/product/manage/pageManage?page=1&rows=2
成功访问

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值