How to Add a Custom PostgreSQL Plugin to Nacos 2.2+ via SPI
Starting with Nacos 2.2.0, you can inject multiple data source plugins via the SPI mechanism; this guide walks through adding a PostgreSQL plugin, importing the required Maven dependencies, loading the database script, configuring connection details, and setting the datasource platform in application.properties.
Nacos from version 2.2.0 can inject multiple data sources via the SPI mechanism; after adding the corresponding data source implementation, you can select the plugin to load at startup by setting the spring.datasource.platform property in application.properties.
Nacos officially provides default implementations for MySQL and Derby; other database types require custom extensions as described below.
Custom PostgreSQL Plugin
1. Add PostgreSQL plugin
The dependency has been uploaded to Maven Central; do not use the Alibaba Cloud proxy.
<dependency>
<groupId>com.pig4cloud.plugin</groupId>
<artifactId>nacos-datasource-plugin-pg</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>2. Import Nacos PostgreSQL database script
Click to download Nacos PostgreSQL database script [1]
3. Configure Nacos datasource connection information
db:
num: 1
url:
0: jdbc:postgresql://172.27.0.5:5432/pigxx_config
user:
0: postgres
password:
0: 123456
pool:
config:
driver-class-name: org.postgresql.Driver4. Specify Nacos datasource platform
spring:
datasource:
platform: postgresqlReference Materials
[1] Click to download Nacos PostgreSQL: https://minio.pigx.vip/oss/202212/1671184224.sql
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
