Fork me on GitHub

Cannot load driver class: org.postgresql.Driver

Cannot load driver class: org.postgresql.Driver


 

一、背景介绍

近期需要将一个前后端不分离的 SpringMVC 工程,重构为前后端分离的工程,前端用 Vue框架,后端使用 SpringBoot 框架。

 

二、问题说明

在启动 SpringBoot 服务时,日志报错“Cannot load driver class: org.postgresql.Driver

 

三、解决方案

1、在 pom.xml 文件中引入 postgresql

        <!-- postgresql  -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>42.3.1</scope>
        </dependency>

 

2、增加拦截器 MybatisPlusInterceptor

复制代码
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisPlusConfig {

    /**
     * 插件配置
     *
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // 向MyBatis-Plus的过滤器链中添加分页拦截器,需要设置数据库类型(主要用于分页方言)
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL));
//        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        // 添加乐观锁拦截器
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
复制代码

 

posted @   龙凌云端  阅读(1600)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2022-02-16 Intellij IDEA HTTP Request 请求设置Cookie
点击右上角即可分享
微信分享提示