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.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
How to Add a Custom PostgreSQL Plugin to Nacos 2.2+ via SPI

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.Driver

4. Specify Nacos datasource platform

spring:
  datasource:
    platform: postgresql

Reference Materials

[1] Click to download Nacos PostgreSQL: https://minio.pigx.vip/oss/202212/1671184224.sql

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

pluginNacospostgresqlSPIDataSource
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.