Nacos2.1.2源码修改支持高斯,postresql
1、下载代码
git clone https://github.com/alibaba/nacos.git -b 2.1.2
或
git clone https://github.com/alibaba/nacos.git
2、maven命令执行下试试能不能打包
mvn -Prelease-nacos -Dmaven.test.skip=true -Drat.skip=true clean install -U
或
mvn -Prelease-nacos ‘-Dmaven.test.skip=true’ ‘-Drat.skip=true’ clean install -U
如果com.alibaba.nacos.consistency.ProtoMessageUtil编译报错,或提示com.谷歌.protobuf:protoc不存在之类的,手动下载protoc-3.16.3-win64.zip文件,把protoc.exe改成截图名字,放到maven路径中
下载路径:
https://github.com/protocolbuffers/protobuf/releases(如果不对可以百度下,白天不稳定,晚上还行)
打包的结果在distribution中
3、添加驱动jar包
打包完成后,试试能不能启动,程序能不能注册,然后开始改代码支持高斯或postresql,本文以高斯为例
① /pom.xml
postgresql的
<properties>
···
<postgresql.version>42.3.3</postgresql.version>
···
</properties>
···
<dependencyManagement>
<dependencies>
···
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
···
</dependencies>
</dependencyManagement>
高斯的
<properties>
···
<opengauss.version>2.0.0</opengauss.version>
···
</properties>
···
<dependencyManagement>
<dependencies>
···
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
<version>${opengauss.version}</version>
</dependency>
···
</dependencies>
</dependencyManagement>
② /config/pom.xml
postgresql的
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
高斯的
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
</dependency>
③ /naming/pom.xml
postgresql的
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
高斯的
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
</dependency>
4、 添加PostgreSQL驱动代码
高斯的驱动代码和PostgreSQL是一模一样的,这里只写postgresql的
① PropertiesConstant.java
public static final String MYSQL = "mysql";
public static final String POSTGRESQL = "postgresql";
② PropertyUtil.java#loadSetting
③ ExternalDataSourceProperties.java
if (PropertiesConstant.POSTGRESQL.equalsIgnoreCase(
EnvUtil.getProperty(PropertiesConstant.SPRING_DATASOURCE_PLATFORM))) {
driverClassName = JDBC_DRIVER_NAME_POSTGRESQL;
}
④ StartingApplicationListener.java
private static final String DATABASE_POSTGRESQL = "postgresql";
以下为#judgeStorageMode方法内
5、 兼容PostgreSQL 语句
① 主键
# 全局替换:
Statement.RETURN_GENERATED_KEYS 替换为 new String[]{"id"}
# 由于postgresql无法通过Statement.RETURN_GENERATED_KEYS获取主键,因此只能显示的指定要寻找的主键
② LIKE
当前2.1.2版本只有两个地方,都在/plugin-default-impl/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence下
① ExternalRolePersistServiceImpl#findRolesLikeRoleName
② ExternalUserPersistServiceImpl#findUserLikeUsername
#如上图类似替换
LIKE '%' ? '%' 替换成 LIKE ?
new String[] {username} 替换成 new String[] {String.format("%%%s%%", username)}
# LIKE '%' '' '%'的方式,mysql可用,但并非标准sql
# LIKE '%%'的方式,这是标准sql,因此mysql与postgresql都可使用
③ LIMIT
# 全局替换:
LIMIT ?, ? 替换为 OFFSET ? LIMIT ?
LIMIT ?,? 替换为 OFFSET ? LIMIT ?
LIMIT \\?,\\? 替换为 OFFSET \\? LIMIT \\?
# LIMIT ?,? 是mysql可用,但并非标准sql
# OFFSET ? LIMIT ? 是sql,因此mysql与postgresql都可使用
还有一个较为特殊
ExternalStoragePaginationHelperImpl#fetchPage
String selectSql;
if (isDerby()) {
selectSql = sqlFetchRows " OFFSET " startRow " ROWS FETCH NEXT " pageSize " ROWS ONLY";
} else if (lastMaxId != null) {
// PostgreSQL support
selectSql = sqlFetchRows " AND id > " lastMaxId " ORDER BY id ASC" " LIMIT " pageSize " OFFSET " 0;
} else {
// PostgreSQL support
selectSql = sqlFetchRows " LIMIT " pageSize " OFFSET " startRow;
}
6、配置文件
剩下的就是
application.properties
nacos-postgresql.sql
的问题了
① application.properties
spring.datasource.platform=postgresql
db.url.0=jdbc:postgresql://127.0.0.1:5432/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=postgres
db.password.0=nacos
② nacos-postgresql.sql
参考文档:
nacos如何以集群模式启动
Unknown lifecycle phase “.test.skip=true“. You must specify a valid lifecycl
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhfkfbaj
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01