Nacos-2.4.0最新版本postgresql插件打包编译成功运行

打印 上一主题 下一主题

主题 1051|帖子 1051|积分 3153

Nacos 2.4.0 


  1、下载Nacos最新版(2.4.0)的postgresql插件源码地址

(特殊注意分支选择,根据更新时间判断,肯定要选择最新分支):

master分支https://github.com/nacos-group/nacos-plugin.git
https://github.com/nacos-group/nacos-plugin.git


开发者develop地址:khttps://github.com/nacos-group/nacos-plugin.git
https://github.com/nacos-group/nacos-plugin.git


 2、idea打开
(1)首先地一步,很重要
修改父工程的pom文件


(2)打开nacos-datasource-plugin-ext下的nacos-postgresql-datasource-plugin-ext

新增一个enums文件以及修改一个类即可完成Nacos最新版的postgresql插件正常适配。

然后:将新增的枚举放入enums包下,该枚举主要是用于覆盖mysql的NOW(3)函数,因为该函数只有mysql才支持,postgresql等数据库不支持,因此需要去掉NOW(3)函数中的参数,如下所示:


  1. package com.alibaba.nacos.plugin.datasource.enums;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. public enum TrustedPostgreSqlFunctionEnum {
  5.     /**sange
  6.      * NOW().
  7.      */
  8.     NOW("NOW()", "NOW()");
  9.     private static final Map<String, TrustedPostgreSqlFunctionEnum> LOOKUP_MAP = new HashMap<>();
  10.     static {
  11.         for (TrustedPostgreSqlFunctionEnum entry : TrustedPostgreSqlFunctionEnum.values()) {
  12.             LOOKUP_MAP.put(entry.functionName, entry);
  13.         }
  14.     }
  15.     private final String functionName;
  16.     private final String function;
  17.     TrustedPostgreSqlFunctionEnum(String functionName, String function) {
  18.         this.functionName = functionName;
  19.         this.function = function;
  20.     }
  21.     /**
  22.      * Get the function name.
  23.      *
  24.      * @param functionName function name
  25.      * @return function
  26.      */
  27.     public static String getFunctionByName(String functionName) {
  28.         TrustedPostgreSqlFunctionEnum entry = LOOKUP_MAP.get(functionName);
  29.         if (entry != null) {
  30.             return entry.function;
  31.         }
  32.         throw new IllegalArgumentException(String.format("Invalid function name: %s", functionName));
  33.     }
  34. }
复制代码
修改ConfigInfoMapperByPostgresql组件 ,该类中新增一个构造函数,如下圖所示
  1. /*
  2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *      http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.alibaba.nacos.plugin.datasource.impl.postgresql;
  17. import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant;
  18. import com.alibaba.nacos.plugin.datasource.enums.TrustedPostgreSqlFunctionEnum;
  19. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoMapper;
  20. /**
  21. * The postgresql implementation of ConfigInfoMapper.
  22. *
  23. * @author Sange
  24. **/
  25. public class ConfigInfoMapperByPostgresql extends BaseConfigInfoMapper {
  26.     /**
  27.      * 解决NOW(integer)错误问题
  28.      * @author sange
  29.      * @since 2024-08-15 00:00
  30.      * @param functionName
  31.      * @return
  32.      * @see
  33.      */
  34.     @Override
  35.     public String getFunction(String functionName)
  36.     {
  37.         return TrustedPostgreSqlFunctionEnum.getFunctionByName(functionName);
  38.     }
  39.     @Override
  40.     public String getDataSource() {
  41.         return DatabaseTypeConstant.POSTGRESQL;
  42.     }
  43.    
  44. }
复制代码
3、最后,PostgreSQL插件编译打包


4、下载最新nacos2.4.0服务,把PostgreSQL插件部署放在新建的plugins下即可
最新nacos2.4.0地址:
官网:Nacos Server 下载 | Nacos 官网
https://github.com/alibaba/nacos/releases



nacos最新版2.4.0成功支持postgresql!!亲测,感谢大佬支持,希望对各人有效,点赞吧

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

钜形不锈钢水箱

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表