diff --git a/backend/src/main/java/kr/touroot/global/config/DataSourceConfig.java b/backend/src/main/java/kr/touroot/global/config/DataSourceConfig.java deleted file mode 100644 index 7d6a6d78..00000000 --- a/backend/src/main/java/kr/touroot/global/config/DataSourceConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -package kr.touroot.global.config; - -import com.zaxxer.hikari.HikariDataSource; -import jakarta.persistence.EntityManagerFactory; -import java.util.HashMap; -import java.util.Map; -import javax.sql.DataSource; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Profile; -import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.transaction.PlatformTransactionManager; - -@Configuration -@Profile("prod") -public class DataSourceConfig { - - public static final String WRITER = "writer"; - public static final String READER = "reader"; - - @ConfigurationProperties(prefix = "spring.datasource.writer") - @Bean - public DataSource writerDataSource() { - return DataSourceBuilder.create().type(HikariDataSource.class).build(); - } - - @ConfigurationProperties(prefix = "spring.datasource.reader") - @Bean - public DataSource readerDataSource() { - return DataSourceBuilder.create().type(HikariDataSource.class).build(); - } - - @DependsOn({"writerDataSource", "readerDataSource"}) - @Bean - public DataSource routingDataSource( - @Qualifier("writerDataSource") DataSource writer, - @Qualifier("readerDataSource") DataSource reader) { - DynamicRoutingDataSource routingDataSource = new DynamicRoutingDataSource(); - - Map dataSourceMap = new HashMap<>(); - - dataSourceMap.put(WRITER, writer); - dataSourceMap.put(READER, reader); - - routingDataSource.setTargetDataSources(dataSourceMap); - routingDataSource.setDefaultTargetDataSource(writer); - - return routingDataSource; - } - - @DependsOn({"routingDataSource"}) - @Primary - @Bean - public DataSource dataSource(DataSource routingDataSource) { - return new LazyConnectionDataSourceProxy(routingDataSource); - } - - @Bean - public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { - JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(); - jpaTransactionManager.setEntityManagerFactory(entityManagerFactory); - return jpaTransactionManager; - } -} diff --git a/backend/src/main/java/kr/touroot/global/config/DynamicRoutingDataSource.java b/backend/src/main/java/kr/touroot/global/config/DynamicRoutingDataSource.java deleted file mode 100644 index f27009a3..00000000 --- a/backend/src/main/java/kr/touroot/global/config/DynamicRoutingDataSource.java +++ /dev/null @@ -1,16 +0,0 @@ -package kr.touroot.global.config; - -import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; -import org.springframework.transaction.support.TransactionSynchronizationManager; - -public class DynamicRoutingDataSource extends AbstractRoutingDataSource { - - @Override - protected Object determineCurrentLookupKey() { - if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) { - return DataSourceConfig.READER; - } - return DataSourceConfig.WRITER; - } -} - diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index a27c4260..f51144f5 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -156,16 +156,10 @@ spring: console: enabled: false datasource: - writer: - jdbc-url: ENC(WmWa9T4FlLD0SWKenUhPZgRaUOEcYFt9tsw5MfpOmGfHF5lFMXiYCGElb3S4NBzWfpIxg3daIlhdEgUJaMv4CjmKPJzt2Mt3f/SPOI8rlMHwSA2IrjFw90mHPWJsGO2WPsAZEOX6TeNVpiIhE4nM2w==) - username: ENC(OD+ZUOLOgfa1s4CpW8wmCA==) - password: ENC(SvYVLaigwGxQjPS1yZKaqs4mDC4jUT2f) - driver-class-name: com.mysql.cj.jdbc.Driver - reader: - jdbc-url: ENC(K1rG1kXZV6c/xdrCt4Q/ANwoRneNZjXTppm65H/cuOjDnGNF8X+80yh7FIAvIbrP74royecVW18xk1O3gJAohEudC486T59hYpNJv2HaTiOJBavO5c9sH6UNbFN0kFYyT1nz9Y2uOkUt71fkW2YQ4A==) - username: ENC(7ap5OS9J40A2EaOxU/Qxyg==) - password: ENC(a79pqVIy4+TknqeGj6qtLumkNltqjcx5) - driver-class-name: com.mysql.cj.jdbc.Driver + driver-class-name: com.mysql.cj.jdbc.Driver + url: ENC(zfwbTfLkDkl/NeNTemoN+aK/VoS0rd6H2yFh+r6rKRIfj3IlYgVy32Y/0CfSdqXJaN6TyOOcVRs=) + username: ENC(JR+N+a5mb3AomBo+3xUE9A==) + password: ENC(3dbjjcIxMU86kQ3iU6zId/hLJzLM6KF+82dEd4g7/+c=) jpa: show-sql: false properties: