数据库

    • 描述
    • 基本增删改查
      • Db + Record 模式
      • Model 映射方式
      • Columns 查询方式
    • 关联查询
    • 分页查询
    • 一对一、一对多、多对一、多对对
    • 事务操作
    • 多数据源
    • 读写分离
    • 分库分表
    • 分布式事务

    描述

    Jboot 的数据库是依赖 JFinal 的 ORM 做基本的数据库操作,同时依赖 apahce-sphere 来做分库、分表和依赖 Seata 来做分布式事务。因此,在使用 Jboot 操作数据库的时候,建议对 JFinal 的 ORM 功能和 Apache Sharding-Sphere 有所了解。

    JFinal 操作数据库,提供了两种方式对数据库进行操作,他们分别是:

    • Db + Record 方式
    • Model 映射方式

    参考 JFinal 的文档:https://jfinal.com/doc/5-5

    Model是 MVC 模式中的 M 部分。以下是 Model 定义示例代码:

    BaseUser:

    1. public void setId(java.lang.Long id) {
    2. set("id", id);
    3. }
    4. public java.lang.Long getId() {
    5. return getLong("id");
    6. }
    7. // other getter setter ...
    8. }

    需要注意的是:

    • 以上的 UserBaseUser 都是通过代码生成器自动生成的,无需手写。
    • 多次执行代码生成器,User 代码不会被覆盖,但是 BaseUser 会被重新覆盖,因此,请不要在 BaseUser 手写任何代码。

    一般情况下,在正式的项目里,代码分层还需要 Service 层来对业务逻辑进行处理。

    UserService 代码如下:

    1. public class UserService extends JbootServiceBase<User> {
    2. // 不需要做任何的实现
    3. }

    以上的 UserService , 只需要继承 JbootServiceBase<User> ,我们不需要编写任何实现代码,就可以拥有基本的增删改查的功能。

    以下是示例代码:

    1. //创建 UserService
    2. UserService userService = new UserService();
    3. // 创建name属性为James,age属性为25的User对象并添加到数据库
    4. User user = new User().set("name", "James").set("age", 25);
    5. userService.save(user);
    6. // 删除id值为25的User
    7. userService.deleteById(25);
    8. // 查询id值为25的User将其name属性改为James并更新到数据库
    9. User user = userService.findById(25);
    10. user.set("name", "James");
    11. userService.update(user);
    12. // 分页查询user,当前页号为1,每页10个user
    13. Page<User> userPage = userService.paginate(1, 10);

    在 JFinal 的基础上上,Jboot 提供了一套更加便利的查询方法,根据列查询。

    比如,一个 tb_user 表中有以下字段:

    1. CREATE TABLE `user` (
    2. `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    3. `username` varchar(128) DEFAULT NULL COMMENT '登录名',
    4. `nickname` varchar(128) DEFAULT NULL COMMENT '昵称',
    5. `realname` varchar(128) DEFAULT NULL COMMENT '实名',
    6. `email` varchar(64) DEFAULT NULL COMMENT '邮件',
    7. `mobile` varchar(32) DEFAULT NULL COMMENT '手机电话',
    8. `gender` varchar(16) DEFAULT NULL COMMENT '性别',
    9. `signature` varchar(2048) DEFAULT NULL COMMENT '签名',
    10. `birthday` datetime DEFAULT NULL COMMENT '生日',
    11. `company` varchar(256) DEFAULT NULL COMMENT '公司',
    12. `occupation` varchar(256) DEFAULT NULL COMMENT '职位、职业',
    13. `address` varchar(256) DEFAULT NULL COMMENT '地址',
    14. `zipcode` varchar(128) DEFAULT NULL COMMENT '邮政编码',
    15. `site` varchar(256) DEFAULT NULL COMMENT '个人网址',
    16. `graduateschool` varchar(256) DEFAULT NULL COMMENT '毕业学校',
    17. `education` varchar(256) DEFAULT NULL COMMENT '学历',
    18. `avatar` varchar(256) DEFAULT NULL COMMENT '头像',
    19. `idcardtype` varchar(128) DEFAULT NULL COMMENT '证件类型:身份证 护照 军官证等',
    20. `idcard` varchar(128) DEFAULT NULL COMMENT '证件号码',
    21. PRIMARY KEY (`id`)
    22. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户信息表,保存用户信息。';

    假设我们根据 username 查询,可以如下:

    1. String name = "michael";
    2. DAO.findFirstByColumns(Columns.create("username",name));

    当有关联查询的时候,可以使用 DAO 的 join 系列方法,如下:

    1. /**
    2. *查询所有用户,left join 文章表
    3. */
    4. public List<User> findList(){
    5. DAO.leftJoin("article").on("user.id = article.user_id")
    6. .rightJoin("...").on(".....")
    7. .findAll()
    8. }
    9. /**
    10. * 根据用户年龄和文章标题查询
    11. */
    12. public List<User> findListBy(int userAge,String articleTitle){
    13. DAO.leftJoin("article").on("user.id = article.user_id")
    14. .rightJoin("...").on(".....")
    15. .findByColumns(Columns.create().ge("user.age",userAge).like("article.title",articleTitle))
    16. }

    一对一、一对多、多对一、多对对

    在 Jboot 中,提供了 Join 系列方法,我们在 Service 层可以直接使用 Join 进行 一对一、一对多、多对一、多对对 的查询操作。

    假设存在这样的关系:一篇文章只有一个作者,一个作者可以写多篇文章,一篇文章可以归属多个文章分类、一个文章分类有可以包含多篇文章。

    那么,表结构设计如下:

    1. CREATE TABLE `article` (
    2. `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
    3. `author_id` int(11) unsigned DEFAULT NULL COMMENT '文章作者ID',
    4. `title` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '文章标题',
    5. `content` text COLLATE utf8mb4_unicode_ci COMMENT '文章内容',
    6. PRIMARY KEY (`id`)
    7. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

    文章作者表 author :

    1. CREATE TABLE `author` (
    2. `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
    3. `nickname` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '作者昵称',
    4. `email` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '作者邮件',
    5. PRIMARY KEY (`id`)
    6. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

    文章分类表 category :

    1. CREATE TABLE `category` (
    2. `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
    3. `title` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '分类标题',
    4. `description` text COLLATE utf8mb4_unicode_ci COMMENT '分类描述',
    5. PRIMARY KEY (`id`)
    6. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

    文章分类和分类的 多对对关系表: article_category:

    数据内容如下:

    1. INSERT INTO `article` (`id`, `author_id`, `title`, `content`)
    2. VALUES
    3. (1,1,'文章1','内容111'),
    4. (2,1,'文章2','内容2222'),
    5. (3,2,'文章3','内容333'),
    6. (4,2,'文章4','内容444');

    有 4 篇文章。

    1. INSERT INTO `author` (`id`, `nickname`, `email`)
    2. VALUES
    3. (1,'孙悟空','swk@gmail.com'),
    4. (2,'猪八戒','zbj@gmail.com');

    有 2 个作者。

    1. INSERT INTO `category` (`id`, `title`, `description`)
    2. VALUES
    3. (1,'文章分类1','文章分类描述111'),
    4. (2,'文章分类2','文章分类描述222');

    有 2 个文章分类。

    1. INSERT INTO `article_category` (`article_id`, `category_id`)
    2. VALUES
    3. (1,1),
    4. (1,2),
    5. (2,2),
    6. (3,1),
    7. (3,2),
    8. (4,1);

    文章 1 有两个分类;文章 2 有一个分类; 文章 3 有两个分类; 文章 4 有一个分类。

    这样,在我们的代码里应该存在 3 个Service,分别是:

    • ArticleService 用于查询文章相关的服务
    • CategoryService 用于查询文章分类相关的服务
    • AuthorService 用于查询作者的服务

    ArticleService 代码如下:

    1. public class ArticleService extends JbootServiceBase<Article> {
    2. @Inject
    3. private AuthorService authorService;
    4. @Inject
    5. private CategoryService categoryService;
    6. public List<Article> findListWithAuthorAndCategories(){
    7. List<Article> articles = DAO.findAll();
    8. // 查询出每篇文章的作者
    9. authorService.join(articles,"author_id");
    10. // 查询文章的所属分类
    11. categoryService.joinManyByTable(articles,"article_category","article_id","category_id");
    12. return articles;
    13. }
    14. }

    ArticleService 输出的 Json 内容如下:

    1. [
    2. {
    3. "author":{
    4. "nickname":"孙悟空",
    5. "id":1,
    6. "email":"swk@gmail.com"
    7. },
    8. "categoryList":[
    9. {
    10. "description":"文章分类描述111",
    11. "id":1,
    12. "title":"文章分类1"
    13. },
    14. {
    15. "description":"文章分类描述222",
    16. "id":2,
    17. "title":"文章分类2"
    18. }
    19. ],
    20. "id":1,
    21. "authorId":1,
    22. "title":"文章1",
    23. "content":"内容111"
    24. },
    25. {
    26. "author":{
    27. "nickname":"孙悟空",
    28. "id":1,
    29. "email":"swk@gmail.com"
    30. },
    31. {
    32. "description":"文章分类描述222",
    33. "id":2,
    34. "title":"文章分类2"
    35. }
    36. ],
    37. "id":2,
    38. "authorId":1,
    39. "title":"文章2",
    40. "content":"内容2222"
    41. },
    42. {
    43. "author":{
    44. "nickname":"猪八戒",
    45. "id":2,
    46. "email":"zbj@gmail.com"
    47. },
    48. "categoryList":[
    49. {
    50. "description":"文章分类描述111",
    51. "id":1,
    52. "title":"文章分类1"
    53. },
    54. {
    55. "id":2,
    56. "title":"文章分类2"
    57. }
    58. ],
    59. "id":3,
    60. "authorId":2,
    61. "title":"文章3",
    62. "content":"内容333"
    63. },
    64. {
    65. "author":{
    66. "nickname":"猪八戒",
    67. "id":2,
    68. "email":"zbj@gmail.com"
    69. },
    70. "categoryList":[
    71. {
    72. "description":"文章分类描述111",
    73. "id":1,
    74. "title":"文章分类1"
    75. }
    76. ],
    77. "id":4,
    78. "authorId":2,
    79. "title":"文章4",
    80. "content":"内容444"
    81. }
    82. ]

    AuthorService 代码如下:

    1. public class AuthorService extends JbootServiceBase<Author> {
    2. @Inject
    3. private ArticleService articleService;
    4. public List<Author> findListWithArticles(){
    5. List<Author> authors = DAO.findAll();
    6. //查询每个作者的所有文章
    7. articleService.joinMany(authors,"author_id");
    8. return authors;
    9. }
    10. }

    AuthorService 输出的 Json 内容如下:

    1. [
    2. {
    3. "articleList":[
    4. {
    5. "id":1,
    6. "authorId":1,
    7. "title":"文章1",
    8. "content":"内容111"
    9. },
    10. {
    11. "id":2,
    12. "authorId":1,
    13. "title":"文章2",
    14. "content":"内容2222"
    15. }
    16. ],
    17. "nickname":"孙悟空",
    18. "id":1,
    19. "email":"swk@gmail.com"
    20. },
    21. {
    22. "articleList":[
    23. {
    24. "id":3,
    25. "authorId":2,
    26. "title":"文章3",
    27. "content":"内容333"
    28. },
    29. {
    30. "id":4,
    31. "authorId":2,
    32. "title":"文章4",
    33. "content":"内容444"
    34. }
    35. ],
    36. "nickname":"猪八戒",
    37. "id":2,
    38. "email":"zbj@gmail.com"
    39. }
    40. ]

    CategoryService 代码如下:

    1. public class CategoryService extends JbootServiceBase<Category> {
    2. @Inject
    3. private ArticleService articleService;
    4. public List<Category> findListWithArticles(){
    5. List<Category> categories = DAO.findAll();
    6. //查询每个分类的所有文章
    7. articleService.joinManyByTable(categories,"article_category","category_id","article_id");
    8. return categories;
    9. }
    10. }

    CategoryService 输出的 json 内容如下:

    具体代码参考:这里

    默认单数据源的情况下,我们需要在 jboot.properties 添加如下配置:

    1. jboot.datasource.type=mysql
    2. jboot.datasource.url=jdbc:mysql://127.0.0.1:3306/jbootdemo
    3. jboot.datasource.user=root
    4. jboot.datasource.password=your_password
    1. jboot.datasource.a1.type=mysql
    2. jboot.datasource.a1.url=jdbc:mysql://127.0.0.1:3306/jboot1
    3. jboot.datasource.a1.user=root
    4. jboot.datasource.a1.password=your_password
    5. jboot.datasource.a2.type=mysql
    6. jboot.datasource.a2.url=jdbc:mysql://127.0.0.1:3306/jboot2
    7. jboot.datasource.a2.user=root
    8. jboot.datasource.a2.password=your_password

    这表示,我们又增加了数据源 a1 和数据源 a2,在使用的时候,我们只需要做一下使用:

    1. Company company = new Company();
    2. company.setCid("1");
    3. company.setName("name");
    4. company.use("a1").save();

    company.use("a1").save(); 表示使用数据源 a1 进行保存。

    需要注意的是:

    在多数据源应用中,很多时候,我们的一个 Model 只有对应一个数据源,而不是一个 Model 对应多个数据源。假设 company 只有在 a1 数据源中存在,在其他数据源并不存在,我们需要把 a1 数据源的配置修改如下:

    1. jboot.datasource.a1.type=mysql
    2. jboot.datasource.a1.url=jdbc:mysql://127.0.0.1:3306/jboot1
    3. jboot.datasource.a1.user=root
    4. jboot.datasource.a1.password=your_password
    5. jboot.datasource.a1.table=company
    6. jboot.datasource.a2.type=mysql
    7. jboot.datasource.a2.url=jdbc:mysql://127.0.0.1:3306/jboot2
    8. jboot.datasource.a2.user=root
    9. jboot.datasource.a2.password=your_password
    10. jboot.datasource.a2.table=user,xxx (其他非company表)

    这样,companya1 数据源中存在,Jboot在初始化的时候,并不会去检查 company 在其他数据源中是否存在,同时,代码操作 company 的时候,不再需要 use() ,代码如下:

    1. Company company = new Company();
    2. company.setCid("1");
    3. company.setName("name");
    4. //company.use("a1").save();
    5. company.save();

    代码中不再需要 use("a1") 指定数据源,因为 company 表只有一个数据源。

    更多关于 datasource 的配置如下:

    1. jboot.datasource.name //数据源名称
    2. jboot.datasource.type //数据源类型
    3. jboot.datasource.url //数据源URL地址
    4. jboot.datasource.user
    5. jboot.datasource.password
    6. jboot.datasource.driverClassName = com.mysql.jdbc.Driver
    7. jboot.datasource.connectionInitSql
    8. jboot.datasource.poolName
    9. jboot.datasource.cachePrepStmts = true
    10. jboot.datasource.prepStmtCacheSize = 500
    11. jboot.datasource.prepStmtCacheSqlLimit = 2048
    12. jboot.datasource.maximumPoolSize = 10
    13. jboot.datasource.maxLifetime
    14. jboot.datasource.idleTimeout
    15. jboot.datasource.minimumIdle = 0
    16. jboot.datasource.sqlTemplatePath // sql 模板存放路径,用到 jfinal sql独立文件的时候
    17. jboot.datasource.sqlTemplate
    18. jboot.datasource.factory
    19. jboot.datasource.shardingConfigYaml //分库分表的配置文件
    20. jboot.datasource.dbProFactory
    21. jboot.datasource.containerFactory
    22. jboot.datasource.transactionLevel
    23. jboot.datasource.table //此数据源包含哪些表
    24. jboot.datasource.exTable //该数据源排除哪些表
    25. jboot.datasource.dialectClass
    26. jboot.datasource.activeRecordPluginClass
    27. jboot.datasource.needAddMapping = true //是否需要添加到映射,当不添加映射的时候,只能通过 model.use("xxx").save()这种方式去调用该数据源

    读写分离

    在 Jboot 应用中,读写分离建议使用两个数据源,分别是读的数据源和写的数据源,写的数据源必须支持可读可写。

    在应用中,在某些场景下我们需要从只读数据源读取数据的时候,通过 DAO.use('只读数据源的名称').find(...) 就可以。

    Jboot 的分库分表功能使用了 Sharding-jdbc 实现的,若在 Jboot 应用在需要用到分库分表功能,需要添加 jboot.datasource.shardingConfigYaml = xxx.yaml 的配置,其中 xxx.yaml 配置需要放在 classpath 目录下,配置内容参考:https://shardingsphere.apache.org/document/current/cn/manual/sharding-jdbc/configuration/config-yaml/

    注意: 当在 jboot.properties 文件配置 jboot.datasource.shardingConfigYaml = xxx.yaml之后,不再需要在 jboot.properties 配置 jboot.datasource.urljboot.datasource.userjboot.datasource.password 等,这些配置都转义到 xxx.yaml 里进行配置了。

    分布式事务

    Jboot 的分布式事务依赖 Seata 来进行实现,在开始分布式事务之前,请先做好 Seata 的相关配置。

    • 创建 Seata 数据库
    • 启动 Seata

    参考:https://github.com/seata/seata/wiki/Quick-Start

    正常启动 Seata 之后,需要在 jboot.properties 配置文件添加如下配置

    1. jboot.rpc.filter = seata
    2. jboot.rpc.type = dubbo
    3. jboot.seata.enable = true
    4. jboot.seata.failureHandler = com.alibaba.io.seata.tm.api.DefaultFailureHandlerImpl
    5. jboot.seata.applicationId = Dubbo_Seata_Account_Service
    6. jboot.seata.txServiceGroup = dubbo_seata_tx_group

    同时,在 resource 目录下添加 registry.conf 文件,用于对 seata 进行 registry 配置,内容如下:

    1. registry {
    2. # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
    3. type = "file"
    4. nacos {
    5. serverAddr = "localhost"
    6. namespace = ""
    7. cluster = "default"
    8. }
    9. eureka {
    10. application = "default"
    11. weight = "1"
    12. }
    13. redis {
    14. serverAddr = "localhost:6379"
    15. db = "0"
    16. }
    17. zk {
    18. cluster = "default"
    19. serverAddr = "127.0.0.1:2181"
    20. session.timeout = 6000
    21. connect.timeout = 2000
    22. }
    23. consul {
    24. cluster = "default"
    25. serverAddr = "127.0.0.1:8500"
    26. }
    27. etcd3 {
    28. cluster = "default"
    29. serverAddr = "http://localhost:2379"
    30. }
    31. sofa {
    32. serverAddr = "127.0.0.1:9603"
    33. application = "default"
    34. region = "DEFAULT_ZONE"
    35. datacenter = "DefaultDataCenter"
    36. cluster = "default"
    37. group = "SEATA_GROUP"
    38. addressWaitTime = "3000"
    39. }
    40. file {
    41. name = "file.conf"
    42. }
    43. }
    44. config {
    45. # file、nacos 、apollo、zk、consul、etcd3
    46. type = "file"
    47. nacos {
    48. serverAddr = "localhost"
    49. namespace = ""
    50. }
    51. consul {
    52. serverAddr = "127.0.0.1:8500"
    53. }
    54. apollo {
    55. app.id = "seata-server"
    56. apollo.meta = "http://192.168.1.204:8801"
    57. }
    58. zk {
    59. serverAddr = "127.0.0.1:2181"
    60. session.timeout = 6000
    61. connect.timeout = 2000
    62. }
    63. etcd3 {
    64. serverAddr = "http://localhost:2379"
    65. }
    66. file {
    67. name = "file.conf"
    68. }
    69. }

    同时,在 resource 目录下添加 file.conf 文件,内容如下:

    1. transport {
    2. # tcp udt unix-domain-socket
    3. type = "TCP"
    4. #NIO NATIVE
    5. server = "NIO"
    6. #enable heartbeat
    7. heartbeat = true
    8. #thread factory for netty
    9. thread-factory {
    10. boss-thread-prefix = "NettyBoss"
    11. worker-thread-prefix = "NettyServerNIOWorker"
    12. server-executor-thread-prefix = "NettyServerBizHandler"
    13. share-boss-worker = false
    14. client-selector-thread-prefix = "NettyClientSelector"
    15. client-selector-thread-size = 1
    16. client-worker-thread-prefix = "NettyClientWorkerThread"
    17. # netty boss thread size,will not be used for UDT
    18. boss-thread-size = 1
    19. #auto default pin or 8
    20. worker-thread-size = 8
    21. }
    22. shutdown {
    23. # when destroy server, wait seconds
    24. wait = 3
    25. }
    26. serialization = "seata"
    27. compressor = "none"
    28. }
    29. service {
    30. #vgroup->rgroup
    31. vgroup_mapping.dubbo_seata_tx_group = "default"
    32. #only support single node
    33. default.grouplist = "127.0.0.1:8091"
    34. #degrade current not support
    35. enableDegrade = false
    36. #disable
    37. disable = false
    38. #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
    39. max.commit.retry.timeout = "-1"
    40. max.rollback.retry.timeout = "-1"
    41. }
    42. client {
    43. async.commit.buffer.limit = 10000
    44. lock {
    45. retry.internal = 10
    46. retry.times = 30
    47. }
    48. report.retry.count = 5
    49. tm.commit.retry.count = 1
    50. tm.rollback.retry.count = 1
    51. }
    52. ## transaction log store
    53. store {
    54. ## store mode: file、db
    55. mode = "file"
    56. ## file store
    57. file {
    58. dir = "sessionStore"
    59. # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    60. max-branch-session-size = 16384
    61. # globe session size , if exceeded throws exceptions
    62. max-global-session-size = 512
    63. # file buffer size , if exceeded allocate new buffer
    64. file-write-buffer-cache-size = 16384
    65. # when recover batch read size
    66. session.reload.read_size = 100
    67. # async, sync
    68. flush-disk-mode = async
    69. }
    70. ## database store
    71. db {
    72. ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
    73. datasource = "dbcp"
    74. ## mysql/oracle/h2/oceanbase etc.
    75. db-type = "mysql"
    76. driver-class-name = "com.mysql.jdbc.Driver"
    77. url = "jdbc:mysql://127.0.0.1:3306/seata"
    78. user = "mysql"
    79. password = "mysql"
    80. min-conn = 1
    81. max-conn = 3
    82. global.table = "global_table"
    83. branch.table = "branch_table"
    84. lock-table = "lock_table"
    85. query-limit = 100
    86. }
    87. }
    88. lock {
    89. ## the lock store mode: local、remote
    90. mode = "remote"
    91. local {
    92. ## store locks in user's database
    93. }
    94. remote {
    95. ## store locks in the seata's server
    96. }
    97. }
    98. recovery {
    99. #schedule committing retry period in milliseconds
    100. committing-retry-period = 1000
    101. #schedule asyn committing retry period in milliseconds
    102. asyn-committing-retry-period = 1000
    103. #schedule rollbacking retry period in milliseconds
    104. rollbacking-retry-period = 1000
    105. #schedule timeout retry period in milliseconds
    106. timeout-retry-period = 1000
    107. }
    108. transaction {
    109. undo.data.validation = true
    110. undo.log.serialization = "jackson"
    111. undo.log.save.days = 7
    112. #schedule delete expired undo_log in milliseconds
    113. undo.log.delete.period = 86400000
    114. undo.log.table = "undo_log"
    115. }
    116. ## metrics settings
    117. metrics {
    118. enabled = false
    119. registry-type = "compact"
    120. # multi exporters use comma divided
    121. exporter-list = "prometheus"
    122. exporter-prometheus-port = 9898
    123. }
    124. support {
    125. ## spring
    126. spring {
    127. # auto proxy the DataSource bean
    128. datasource.autoproxy = false

    以上配置完毕后如何使用呢?点击 查看代码实例。