fix: add @Primary PG DataSource/JdbcTemplate to prevent CH bean conflict
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m6s
CI / docker (push) Successful in 41s
CI / deploy (push) Has been skipped
CI / deploy-feature (push) Successful in 38s
CI / cleanup-branch (pull_request) Has been skipped
CI / build (pull_request) Successful in 1m51s
CI / docker (pull_request) Has been skipped
CI / deploy (pull_request) Has been skipped
CI / deploy-feature (pull_request) Has been skipped
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m6s
CI / docker (push) Successful in 41s
CI / deploy (push) Has been skipped
CI / deploy-feature (push) Successful in 38s
CI / cleanup-branch (pull_request) Has been skipped
CI / build (pull_request) Successful in 1m51s
CI / docker (pull_request) Has been skipped
CI / deploy (pull_request) Has been skipped
CI / deploy-feature (pull_request) Has been skipped
When clickhouse.enabled=true, the ClickHouse JdbcTemplate bean prevents Spring Boot auto-config from creating the default PG JdbcTemplate. All PG repositories then get the CH JdbcTemplate and fail with "Table cameleer.audit_log does not exist". Fix: explicitly create @Primary DataSource and JdbcTemplate from DataSourceProperties so PG remains the default for unqualified injections. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,11 @@ package com.cameleer3.server.app.config;
|
|||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@@ -15,6 +17,22 @@ import javax.sql.DataSource;
|
|||||||
@ConditionalOnProperty(name = "clickhouse.enabled", havingValue = "true")
|
@ConditionalOnProperty(name = "clickhouse.enabled", havingValue = "true")
|
||||||
public class ClickHouseConfig {
|
public class ClickHouseConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Explicit primary PG DataSource. Required because adding a second DataSource
|
||||||
|
* (ClickHouse) prevents Spring Boot auto-configuration from creating the default one.
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public DataSource dataSource(DataSourceProperties properties) {
|
||||||
|
return properties.initializeDataSourceBuilder().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public JdbcTemplate jdbcTemplate(DataSourceProperties properties) {
|
||||||
|
return new JdbcTemplate(dataSource(properties));
|
||||||
|
}
|
||||||
|
|
||||||
@Bean(name = "clickHouseDataSource")
|
@Bean(name = "clickHouseDataSource")
|
||||||
public DataSource clickHouseDataSource(ClickHouseProperties props) {
|
public DataSource clickHouseDataSource(ClickHouseProperties props) {
|
||||||
HikariDataSource ds = new HikariDataSource();
|
HikariDataSource ds = new HikariDataSource();
|
||||||
|
|||||||
Reference in New Issue
Block a user