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.platformproperty 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.
<code><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></code>2. Import Nacos PostgreSQL database script
Click to download Nacos PostgreSQL database script [1]
3. Configure Nacos datasource connection information
<code>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.Driver</code>4. Specify Nacos datasource platform
<code>spring:
datasource:
platform: postgresql</code>Reference Materials
[1] Click to download Nacos PostgreSQL: https://minio.pigx.vip/oss/202212/1671184224.sql
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.