一 sdk配置操作
1.1 结构
sdk项目目录中只有基础的service类以及mybatis操作数据库的相关文件,service类中包含查询数据库的方法。

说明:
1.2 sdk的pom打包配置
作为公共项目打成jar供其他项目引用,注意被引入的项目不能使用默认的maven-plugin打包,否则引入此jar包的项目编译时会报找不到程序包的错误。

代码
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
</plugins> 
1.3 进行打包
配置完成后使用maven工具进行打包


二 启动引擎项目引用sdk
2.1 启动引擎的结构

2.2 配置pom

2.3 扫描文件配置
@MapperScan同时扫描sdk的dao接口和启动引擎项目的dao接口
@ComponentScan同时注册sdk和启动引擎项目下需要被使用的类

2.4 application配置文件
server:
  port: 8080
spring:
    datasource:
        name: mysql_test
        type: com.alibaba.druid.pool.DruidDataSource
        #druid相关配置
        druid:
          #监控统计拦截的filters
          filters: stat
          driver-class-name: com.mysql.jdbc.Driver
          #基本属性
          url: jdbc:mysql://127.0.0.1:3306/mytestdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
          username: root
          password: cloudiip
          #配置初始化大小/最小/最大
          initial-size: 1
          min-idle: 1
          max-active: 20
          #获取连接等待超时时间
          max-wait: 60000
          #间隔多久进行一次检测,检测需要关闭的空闲连接
          time-between-eviction-runs-millis: 60000
          #一个连接在池中最小生存的时间
          min-evictable-idle-time-millis: 300000
          validation-query: SELECT 'x'
          test-while-idle: true
          test-on-borrow: false
          test-on-return: false
          #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
          pool-prepared-statements: false
          max-pool-prepared-statement-per-connection-size: 20
mybatis:
  mapper-locations: classpath*:mapper/*.xml
  type-aliases-package: com.ljf.lockdemo.model
  #configuration:
    #增加打印sql语句,一般用于本地开发测试
    #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#配置log输出文件
logging:
  config: classpath:logback-spring.xml
distribute:
  lock:
    keep-alive-time: 30
#pagehelper
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
    returnPageInfo: check
 
注意:如果引入的其它的jar并且要使用它对应的mapper/*.xml文件时,要修改mapper-locations配置,使用通配符扫描所有calsspath对应目录下的mapper文件
 mapper-locations: classpath*:mapper/*.xml
2.5 启动测试
1.postman测试

2.查看日志:看到调用sdk中实现查询数据操作的日志。




















