iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >解决springboot整合druid遇到的坑
  • 959
分享到

解决springboot整合druid遇到的坑

2024-04-02 19:04:59 959人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

SpringBoot整合druid的坑 项目环境 springboot 2.1.6.RELEASE jdk 1.8 pom.xml配置 <?xm

SpringBoot整合druid的坑

项目环境

pom.xml配置


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="Http://Maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.test</groupId>
    <artifactId>page</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>page</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <druid.version>1.1.10</druid.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-WEB</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>${druid.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.GitHub.pagehelper/pagehelper-spring-boot-starter -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastJSON</artifactId>
            <version>1.2.28</version>
        </dependency>
        <dependency>
            <groupId>Mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

application.yml


server:
  port: 8001
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      mysql:
        name: mysql
        url: jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
        driver-class-name: com.mysql.cj.jdbc.Driver
        username: root
        passWord: root
        # 下面为连接池的补充设置,应用到上面所有数据源中
        # 初始化大小,最小,最大
        initialSize: 5
        minIdle: 5
        maxActive: 20
        # 配置获取连接等待超时的时间
        maxWait: 60000
#      oracle:
#        name: oracle
#        url: jdbc:oracle:thin:@127.0.0.1:1521:ORCL
#        username: zs
#        password: 123456
#        initialSize: 5
#        minIdle: 5
#        maxActive: 20
#        maxWait: 60000
mybatis:
  mapper-locations:
  - classpath*:mapper
    @Bean
    public ServletReGIStrationBean druidServlet() {
        ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid
    @Bean
    public FilterRegistrationBean druidFilter() {
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new WebStatFilter());
        Map<String, String> initParams = new HashMap<>();
        //设置不拦截的路径  *.cs *.js    /druid/*
        initParams.put("exclusions","*.js,*.CSS,/druid/*");
        bean.setInitParameters(initParams);
        //设置filter拦截 那些请求
        bean.setUrlPatterns(Arrays.asList("/*"));
        return bean;
    }
}

3.2 建立MybatisConfig类


package cn.vp.config;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyBatisConfig {
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return new ConfigurationCustomizer() {
            @Override
            public void customize(org.apache.ibatis.session.Configuration configuration) {
                //-自动使用驼峰命名属性映射字段   userId    user_id
                configuration.setMapUnderscoreToCamelCase(true);
                //使用列别名替换列名 select user as User
                configuration.setUseColumnLabel(true);
            }
        };
    }
}

四,dao层的建立


package cn.vp.dao;
import cn.vp.entity.Department;
import org.apache.ibatis.annotations.*;
@Mapper
public interface DepartmentDao {
    @Insert("INSERT INTO `Department` (`departmentName`) VALUES (#{departmentName})")
    public int aDDDepartment(Department department);
    @Delete("DELETE FROM  department where id=#{id}")
    public int deleteById(Integer id);
    @Update("UPDATE `Department` SET `departmentName`=#{departmentName} WHERE (`id`=#{id})")
    public int updateDepartment(Department department);
    @Select("SELECT  * from department where id=#{id}")
    public Department queryById(@Param("id") Integer id);
}

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: 解决springboot整合druid遇到的坑

本文链接: https://www.lsjlt.com/news/132421.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 解决springboot整合druid遇到的坑
    springboot整合druid的坑 项目环境 springboot 2.1.6.RELEASE jdk 1.8 pom.xml配置 <?xm...
    99+
    2024-04-02
  • 解决SpringBoot整合RocketMQ遇到的坑
    应用场景 在实现RocketMQ消费时,一般会用到@RocketMQMessageListener注解定义Group、Topic以及selectorExpression(数...
    99+
    2024-04-02
  • spring/springboot整合curator遇到的坑及解决
    目录整个代码可项目遇到了两个问题解决办法近期本人在搭建自己的调度平台项目使用到了zookeeper做执行器自动注册中心时,使用到了springboot2.0+curator4.0版本...
    99+
    2024-04-02
  • SpringBoot整合RocketMQ遇到的坑怎么解决
    本篇内容主要讲解“SpringBoot整合RocketMQ遇到的坑怎么解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“SpringBoot整合RocketMQ遇到的坑怎么解决”吧!应用场景在实...
    99+
    2023-06-08
  • springboot整合spring-data-redis遇到的坑
    描述使用springboot整合redis,使用默认的序列化配置,然后使用redis-client去查询时查询不到相应的key.使用工具发现,key的前面多了\xAC\xED\x00\x05t\x00!这样一个串.而且value也是不能直观...
    99+
    2023-05-31
    spring boot data
  • 解决Spring boot 整合Junit遇到的坑
    目录这是我在使用springboot整合Junit的时候遇到的坑1.在pom.xml中添加junit环境的依赖2.在src/test/java下建立测试类3.自己编写的启动类Spri...
    99+
    2024-04-02
  • 如何解决SpringBoot整合RocketMQ遇到的问题
    本篇内容主要讲解“如何解决SpringBoot整合RocketMQ遇到的问题”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何解决SpringBoot整合RocketMQ遇到的问题”吧!应用场景...
    99+
    2023-06-20
  • 解决SpringBoot整合ElasticSearch遇到的连接问题
    SpringBoot整合ElasticSearch的连接问题 failed to load elasticsearch nodes : org.elasticsearch.clie...
    99+
    2024-04-02
  • SpringBoot遇到的坑@Qualifier报红的解决
    目录SpringBoot遇到的坑@Qualifier报红解决方法SpringBoot注解@Qualifier用法SpringBoot遇到的坑@Qualifier报红 今天写项目的时候...
    99+
    2024-04-02
  • SpringBoot测试junit遇到的坑及解决
    目录一、NullPointerException原因解决二、org.springframework.context.ApplicationContextException三、java...
    99+
    2024-04-02
  • springboot连接sqllite遇到的坑及解决
    目录springboot连接sqllite的坑springboot集成sqlite配置设置springboot集成sqlitespringboot连接sqllite的坑 2021-0...
    99+
    2024-04-02
  • springboot整合freemarker的踩坑及解决
    目录springboot整合freemarker踩坑报错问题原因解决方法springboot freemarker基础配置及使用1.基础配置2.基础使用springboot整合fre...
    99+
    2024-04-02
  • 使用SpringBoot的CommandLineRunner遇到的坑及解决
    目录使用场景两个接口的不同特殊的场景遇到的坑填坑总结使用场景 再应用程序开发过程中,往往我们需要在容器启动的时候执行一些操作。 Spring Boot中提供了CommandLineR...
    99+
    2023-02-13
    使用SpringBoot CommandLineRunner的坑 SpringBoot CommandLineRunner
  • seata springcloud整合教程与遇到的坑
    SEATA概要 seata 是alibaba 出的一款分布式事务管理器,他有侵入性小,实现简单等特点。我们能够使用seata 实现分布式事务管理, 是微服务必备的组件。他可以实现在...
    99+
    2024-04-02
  • 解决SpringBoot整合MybatisPlus分模块管理遇到的bug
    前言 这个Bug前前后后折腾了两天才找到答案,虽说不是完全两天的工作时间在调试这个问题,但是过程也确实曲折,所以做一下记录,也当做一次自我反省 背景 SpringBoot 与 MyB...
    99+
    2024-04-02
  • springboot连接sqllite遇到的坑如何解决
    本篇内容主要讲解“springboot连接sqllite遇到的坑如何解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“springboot连接sqllite遇到的坑如何解决”吧!springbo...
    99+
    2023-07-02
  • 解决SpringBoot配置文件application.yml遇到的坑
    目录配置文件application.yml遇到的坑1.第一个坑,原代码解决办法2.第二个坑,原代码参见下图解决办法配置文件application.yml的注意事项这类似于还有一种配置...
    99+
    2024-04-02
  • SpringBoot整合Druid、Redis的示例详解
    目录1.整合Druid1.1Druid简介1.2添加上 Druid 数据源依赖1.3使用Druid 数据源 2.整合redis2.1添加上 redis依赖2.2yml添加r...
    99+
    2024-04-02
  • SpringBoot整合OpenFeign的坑
    目录项目集成OpenFegin集成OpenFegin依赖实现远程调用解决问题问题描述问题分析问题解决最近,在使用SpringBoot+K8S开发微服务系统,既然使用了K8S,我就不想...
    99+
    2024-04-02
  • springcloudoauth2feign遇到的坑及解决
    目录springcloudoauth2feign遇到的坑客户端模式基于springsecurityspringcloud微服务增加oauth2权限后feign调用报null一般是这样...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作