SpringBoot整合SpringBatch项目,已将代码开源至github,访问地址:https://github.com/cmlbeliever/SpringBatch 欢迎star or fork!css
最近因为项目须要开始研究SpringBatch,而且将其整合到SpringBoot中,去除繁杂的xml配置,使用注解,基于约定优于配置的思路进行整合。作到能够很是简单的根据业务需求进行配置,添加新的Batch。java
该项目的主要整合了Spring,SpringBoot,Mybatis,DBCP等经常使用框架,支持DB读写分离。一个注解便可添加新的Batch。git
Batch配置约定说明:github
一、/db目录下的sql为当前项目所用到的ddlsql
二、项目运行参数说明markdown
- batchName(required) : 该batch名称,例如运行bat00X,则参数为:batchName=bat00X
- logging.config(optional) : log配置所在的位置,一般本地运行时不须要关心此参数。在发布到开发机或本番时须要传入。格式:logging.config=${filePath},例如运行bat00X,则参数为:logging.config=classpath:logback-bat00X.xml
三、src/main/java工程结构说明mybatis
- com.cml.learning.framework 为框架基础配置包,一般状况不作修改
- com.cml.learning.module 为每一个batch对应的模块信息,须要开发者本身实现
四、src/main/resource工程结构说明app
- application.properties 全局配置properties
- logback.xml 默认的log配
- config/jdbc-r.properties 只读db配置
- config/jdbc-rw.properties 读写db配置
- config/log 每一个batch对应的log配置
- config/module 每一个batch对应的properties配置信息
五、项目约定说明框架
- 每一个batch类都须要添加注解@BatchAnnotation用于标识batch运行环境
每一个batch对应有本身的Configuration,用于配置SpringBatch运行信息ui
全部batch统一在包(com.cml.learning.module)下,根据batch名称定义包名
如: com.cml.learning.module.batch001
每一个batch继承com.cml.learning.framework.module.BaseModule而且实现接口 com.cml.learning.framework.constant.ModuleConst
- 只读Mapper须要继承com.cml.learning.framework.mybatis.marker.ReadMapper,而且Mapper名称以ReadMaper结尾
- 只读Mapper对应的xml以read.sql.xml结尾,且名称为当前batch名,例如bat001的只读xml为:bat001.read.sql.xml
- 读写Mapper须要继承com.cml.learning.framework.mybatis.marker.WriteMapper,而且Mapper名称以WriteMapper结尾
- 读写Mapper对应的xml以write.sql.xml结尾,而且名称为当前batch名,,例如bat001的读写xml为:bat001.write.sql.xml
- DB所对应的bean在每一个batch下的beans包下,如bat001 对应的bean在包:com.cml.learning.module.bat001.beans下,Mybatis 会自动扫描此包下对应的bean
- processor,reader,writer都有对应的基类,每一个batch下对应的模块都须要继承对应的基类。
该项目会不断完善,若有意见或建议,欢迎提出。