Nacos 2.4.0
1、下载Nacos最新版(2.4.0)的postgresql插件源码地址
(特殊注意分支选择,根据更新时间判断,肯定要选择最新分支):
master分支https://github.com/nacos-group/nacos-plugin.githttps://github.com/nacos-group/nacos-plugin.git
开发者develop地址:khttps://github.com/nacos-group/nacos-plugin.githttps://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!!亲测,感谢大佬支持,希望对各人有效,点赞吧
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |