Coder Social home page Coder Social logo

dynamic-datasource's Introduction

dynamic-dataSource

Dynamic switching dataSource

本项目是用的mybatis 作为ORM框架

在application.properties 中配置主数据源的连接信息

src/main/resources/sql目录下放置的是数据库脚本

src/main/resources/spring/spring-mybatis.xml 配置主库的数据源等信息

spring-mybatis-dynamic.xml 配置的是动态数据源的连接信息

<bean id="sqlSessionFactory_dynamic" class="com.ztkj.core.handler.MySqlSessionFactoryBean"> <property name="dataSource" ref="dynamicDataSource" /> <!-- 指定扫描哪些路径下的配置文件 --> <property name="mapperLocations" value="classpath:mapper2/*.xml"/> </bean>

修改mapperLocations 修改动态数据源的查询语句配置

com.ztkj.core.aspect.DataSourceAspect 是负责切换数据源的拦截器 根据传入的token参数查询相应的数据源,并切换

dynamic-datasource's People

Contributors

jack-zero-wk avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.