apache-shenyu适配oceanbase

2024-08-23 19:55:45 浏览数 (1)

不可乘快而多事,不可因倦而鲜终。——菜根谭

首先docker跑一个实例

代码语言:javascript复制
Github-Id-VampireAchao:~ achao$ docker run -p 2881:2881 --name shenyu-oceanbase -e MINI_MODE=0 -e ROOT_PASSWORD=12345678 -d oceanbase/oceanbase-ce
ed75d5a951daa4eaa8173c43bb65b27e1126f3063488ad1deafead941d6f2ff5
Github-Id-VampireAchao:~ achao$ 

由于oceanbase本身良好的语法兼容性,mysql模式语法不用修改,因此这里只针对驱动进行兼容

https://github.com/apache/shenyu/pull/5617

引入依赖:

代码语言:javascript复制
<dependency>
    <groupId>com.oceanbase</groupId>
    <artifactId>oceanbase-client</artifactId>
    <version>${oceanbase.version}</version>
</dependency>

版本是<oceanbase.version>2.4.12</oceanbase.version>

这边主要是需要注册pagehelper的方言:

代码语言:javascript复制
import com.github.pagehelper.dialect.helper.MySqlDialect;
import com.github.pagehelper.page.PageAutoDialect;
import org.springframework.beans.factory.InitializingBean;

    
    @Configuration
    @ConditionalOnProperty(name = "shenyu.database.dialect", havingValue = "oceanbase")
    static class OceanBaseSQLConfig implements InitializingBean {

        /**
         * Register auto dialect alias.
         */
        @Override
        public void afterPropertiesSet() {
            PageAutoDialect.registerDialectAlias("oceanbase", MySqlDialect.class);
        }
    }

这里还需要额外配置yml

代码语言:javascript复制
spring:
  integration:
    jdbc:
      platform: mysql

0 人点赞