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

Nacos 2.4.0 

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

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

master分支https://github.com/nacos-group/nacos-plugin.giticon-default.png?t=N7T8https://github.com/nacos-group/nacos-plugin.git

开发者develop地址:khttps://github.com/nacos-group/nacos-plugin.giticon-default.png?t=N7T8https://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)函数中的参数,如下所示:

package com.alibaba.nacos.plugin.datasource.enums;

import java.util.HashMap;
import java.util.Map;

public enum TrustedPostgreSqlFunctionEnum {

    /**sange
     * NOW().
     */
    NOW("NOW()", "NOW()");

    private static final Map<String, TrustedPostgreSqlFunctionEnum> LOOKUP_MAP = new HashMap<>();

    static {
        for (TrustedPostgreSqlFunctionEnum entry : TrustedPostgreSqlFunctionEnum.values()) {
            LOOKUP_MAP.put(entry.functionName, entry);
        }
    }

    private final String functionName;

    private final String function;

    TrustedPostgreSqlFunctionEnum(String functionName, String function) {
        this.functionName = functionName;
        this.function = function;
    }

    /**
     * Get the function name.
     *
     * @param functionName function name
     * @return function
     */
    public static String getFunctionByName(String functionName) {
        TrustedPostgreSqlFunctionEnum entry = LOOKUP_MAP.get(functionName);
        if (entry != null) {
            return entry.function;
        }
        throw new IllegalArgumentException(String.format("Invalid function name: %s", functionName));
    }
}

修改ConfigInfoMapperByPostgresql组件 ,该类中新增一个构造函数,如下圖所示

/*
 * Copyright 1999-2022 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.nacos.plugin.datasource.impl.postgresql;

import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant;
import com.alibaba.nacos.plugin.datasource.enums.TrustedPostgreSqlFunctionEnum;
import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoMapper;

/**
 * The postgresql implementation of ConfigInfoMapper.
 *
 * @author Sange
 **/
public class ConfigInfoMapperByPostgresql extends BaseConfigInfoMapper {
    /**
     * 解决NOW(integer)错误问题
     * @author sange
     * @since 2024-08-15 00:00
     * @param functionName
     * @return
     * @see
     */
    @Override
    public String getFunction(String functionName)
    {
        return TrustedPostgreSqlFunctionEnum.getFunctionByName(functionName);
    }

    @Override
    public String getDataSource() {
        return DatabaseTypeConstant.POSTGRESQL;
    }
    
}

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!!亲测,感谢大佬支持,希望对大家有用,点赞吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值