首页 > 其他分享 >Spring boot2 数据访问之Druid数据源+Mybatis

Spring boot2 数据访问之Druid数据源+Mybatis

时间:2023-06-13 17:56:11浏览次数:45  
标签:Spring 数据源 boot Druid Mybatis spring mybatis org starter

Mybatis官方地址

 

1、查找Mybatis 相关starter 官方文档 

这里注意查找指定版本的Starter

 这里以2.2.2为例,查看官方的pom.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
       Copyright 2015-2022 the original author or authors.
       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
-->
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot</artifactId>
    <version>2.2.2</version>
  </parent>
  <artifactId>mybatis-spring-boot-starter</artifactId>
  <name>mybatis-spring-boot-starter</name>
  <properties>
    <module.name>org.mybatis.spring.boot.starter</module.name>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
    </dependency>
  </dependencies>
</project>

提取其中的starter相关信息,如下:

       <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>

添加至目标项目的pom.xml,reload maven,添加了如下依赖项

 查看自动配置类如下:

 i、SqlSessionFactory和SqlSessionFactoryBean类必须存在

ii、有且只有一个DataSource

vi、通过配置项前缀为mybatis和MybatisProperties实例绑定

vii、在DataSourceAutoConfiguration和MybatisLanguageDriverAutoConfiguration之后配置

 

2、相关依赖项

标签:Spring,数据源,boot,Druid,Mybatis,spring,mybatis,org,starter
From: https://www.cnblogs.com/GreenLeaves/p/17478133.html

相关文章

  • springboot~代码风格统计spring-javaformat-maven-plugin插件
    SpringJavaformat是Spring团队开发的一款基于GoogleJavaFormat的代码格式化工具,可以帮助Java开发者自动化进行代码格式化,提高代码质量,降低代码维护成本。SpringJavaformat可以自定义配置文件,支持大量的代码风格配置选项,满足不同项目和团队的需求。还可以与Gradle、Maven、Int......
  • Spring Bean基础
    在接下来的一段时间里,主要分享一些Spring相关的知识文章!Spring官方文档BeanDefinition元信息BeanDefinition是定义Bean的配置元信息接口,主要作用是描述一个Bean,里面存储Bean的相关信息;包括类名、构造器、属性、方法、作用域、自动绑定的模式,生命周期回调等等。概述他的类图继承关......
  • springboot rabbitmq配置
    YMLrabbitmq:host:xxx.xxx.xxx.xxxport:5672virtual-host:devusername:xxxpassword:xxxpublisher-confirm-type:correlatedpublisher-returns:truelistener:direct:acknowledge-mode:autosimple:......
  • 完美解决SpringBoot上传图片之后,需要重服务才能访问
    上传图片后需要重新编译才能访问图片添加一个配置文件WebMvcConfigctrl+shift+alt+/选择Registry,勾选compiler.automake.allow.when.app.running勾选添加一个配置文件WebMvcConfigpackagecom.fans.common.config;importorg.springframework.context.annotation.Configu......
  • window下正常的springboot到mac下运行却报错
    Errorcreatingbeanwithname'defaultValidator'definedinclasspathresource[org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.NoClassDefFoun......
  • 公司已有springboot项目引入swagger
    公司已有springboot项目引入swagger1、swagger介绍官网:https://swagger.io/Swagger是一个用于生成、描述和调用RESTful接口的Web服务。通俗的来讲,Swagger就是将项目中所有(想要暴露的)接口展现在页面上,并且可以进行接口调用和测试的服务2、引入目的Swagger有以下3个重要的作......
  • Quarkus vs. Spring Boot: A head-to-head comparison
    作者:SamuelCatalanohttps://medium.com/@samuelcatalano/quarkus-vs-spring-boot-a-head-to-head-comparison-3b9502c0a345Whenitcomestobuildingmicroservicesandothercloud-nativeapplications,therearemanyoptionsavailabletodevelopers.Twopopularf......
  • 搭建springbootweb环境
    搭建springboot环境(idea环境)实现步骤:1.基础环境配置2.maven配置3.编写第一个程序helloworld(可能有两个小问题)4.运行(jar包运行,命令行运行)一.基础环境配置进入idea,点击file->new->project,在弹出的页面上,选择springinitiallzr并进行相关的配置点击next点击create,完成sp......
  • spring boot连接Mybatis数据库的配置文件(MySql、SQLserver、Oracle)
    序号类型地址1MySQLMySQL操作之概念、SQL约束(一)2MySQLMySQL操作之数据定义语言(DDL)(二)3MySQLMySQL操作之数据操作语言(DML)(三)4MySQLMySQL操作之数据查询语言:(DQL)(四-1)(单表操作)5MySQLMySQL操作之数据查询语言:(DQL)(四-2)(多表查询)6MySQLMySQL操作之数据控制语言:(DC)(五)7MySQLMySQL操作之数......
  • Druid解析SQL获取注释、表明
    一、简介Druid是Java语言中最好的数据库连接池。Druid能够提供强大的监控和扩展功能。文档地址https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98参考地址:https://github.com/alibaba/druid/issues/2457https://github.com/alibaba/druid/issues/2426......