首先实验利用官方插件举行扩展,各种报错后放弃,不如自己修改源码吧。
一、官方办理方案
1、nocos 文档地址:Nacos 配置中央简介, Nacos 是什么 | Nacos 官网
2、官方解答:nacos支持postgresql数据库吗 | Nacos 官网
3、源码下载地址:Release 2.3.0 (Nov 30, 2023) · alibaba/nacos · GitHub
4、Nacos的数据库插件仓库:nacos-plugin/nacos-datasource-plugin-ext at develop · nacos-group/nacos-plugin · GitHub
按照官方的方案,下载插件后,更改pom文件中nacos的版本,之后将插件打成jar包,放到nacos的plugins目录下,更改配置,启动后各种报错找不到方法,遂放弃。
二、更改源码
1、在项目根(nacos-all)下的pom.xml文件中添加如下依靠:
<postgresql.version>42.3.8</postgresql.version>
org.postgresql postgresql ${postgresql.version} 2、在项目标nacos-config-plugin、nacos-persistence模块的pom.xml文件中添加如下依靠:
org.postgresql postgresql 3、在项目标nacos-plugin模块的nacos-datasource-plugin模块com.alibaba.nacos.plugin.datasource.impl包下新建一个包,名为postgresql,拷贝同级包mysql下的所有文件到postgresql包下,修改类名和文件名为xxxByPostgresql,如图
4、将这几个类中LIMIT ?,?的写法为OFFSET ? LIMIT ? 如图
5、在改项目resource目录下,找到com.alibaba.nacos.plugin.datasource.mapper.Mapper文件,在背面追加:
com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoAggrMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoBetaMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigInfoTagMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.ConfigTagsRelationMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.HistoryConfigInfoMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.TenantInfoMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.TenantCapacityMapperByPostgresql
com.alibaba.nacos.plugin.datasource.impl.postgresql.GroupCapacityMapperByPostgresql
如图:
6、在DataSourceConstant类中增加pgsql的常量
- public static final String POSTGRESQL = "postgresql";
复制代码 7、persistence模块,修改PersistenceConstant
- public static final String POSTGRESQL = "postgresql";
复制代码 修改ExternalDataSourceProperties类


代码如下,直接复制粘贴即可:
- /*
- * Copyright 1999-2023 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.persistence.datasource;
- import com.alibaba.nacos.common.utils.CollectionUtils;
- import com.alibaba.nacos.common.utils.Preconditions;
- import com.alibaba.nacos.common.utils.StringUtils;
- import com.zaxxer.hikari.HikariDataSource;
- import org.springframework.boot.context.properties.bind.Bindable;
- import org.springframework.boot.context.properties.bind.Binder;
- import org.springframework.core.env.Environment;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Objects;
- import static com.alibaba.nacos.common.utils.CollectionUtils.getOrDefault;
- /**
- * Properties of external DataSource.
- *
- * @author Nacos
- */
- public class ExternalDataSourceProperties {
-
- private static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
- private static final String TEST_QUERY = "SELECT 1";
-
- private Integer num;
-
- private List<String> url = new ArrayList<>();
-
- private List<String> user = new ArrayList<>();
-
- private List<String> password = new ArrayList<>();
- private String jdbcDriverName;
- public void setJdbcDriverName(String jdbcDriverName) {
- if (StringUtils.isBlank(jdbcDriverName)) {
- this.jdbcDriverName = JDBC_DRIVER_NAME;
- } else {
- this.jdbcDriverName = jdbcDriverName;
- }
- }
-
- public void setNum(Integer num) {
- this.num = num;
- }
-
- public void setUrl(List<String> url) {
- this.url = url;
- }
-
- public void setUser(List<String> user) {
- this.user = user;
- }
-
- public void setPassword(List<String> password) {
- this.password = password;
- }
- /**
- * Build serveral HikariDataSource.
- *
- * @param environment {@link Environment}
- * @param callback Callback function when constructing data source
- * @return List of {@link HikariDataSource}
- */
- List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {
- List<HikariDataS
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |