This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47bfd28
commit 6133f55
Showing
2 changed files
with
101 additions
and
102 deletions.
There are no files selected for viewing
202 changes: 101 additions & 101 deletions
202
src/main/java/com/flab/shoeauction/common/config/RoutingDataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,101 @@ | ||
//package com.flab.shoeauction.common.config; | ||
// | ||
//import static com.flab.shoeauction.common.utils.constants.DataSourceConstants.MASTER; | ||
//import static com.flab.shoeauction.common.utils.constants.DataSourceConstants.SLAVE; | ||
// | ||
//import com.flab.shoeauction.common.db.DynamicRoutingDataSource; | ||
//import com.zaxxer.hikari.HikariDataSource; | ||
//import java.util.HashMap; | ||
//import java.util.Map; | ||
//import javax.persistence.EntityManagerFactory; | ||
//import javax.sql.DataSource; | ||
//import lombok.RequiredArgsConstructor; | ||
//import org.springframework.beans.factory.annotation.Qualifier; | ||
//import org.springframework.boot.context.properties.ConfigurationProperties; | ||
//import org.springframework.boot.jdbc.DataSourceBuilder; | ||
//import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy; | ||
//import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; | ||
//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.core.env.Environment; | ||
//import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; | ||
//import org.springframework.orm.jpa.JpaTransactionManager; | ||
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
//import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||
//import org.springframework.transaction.PlatformTransactionManager; | ||
//import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
// | ||
//@RequiredArgsConstructor | ||
//@Configuration | ||
//@EnableTransactionManagement | ||
//public class RoutingDataSourceConfig { | ||
// | ||
// private final Environment env; | ||
// | ||
// @ConfigurationProperties(prefix = "spring.datasource.hikari.master") | ||
// @Bean | ||
// public DataSource masterDataSource() { | ||
// return DataSourceBuilder.create().type(HikariDataSource.class).build(); | ||
// } | ||
// | ||
// @ConfigurationProperties(prefix = "spring.datasource.hikari.slave") | ||
// @Bean | ||
// public DataSource slaveDataSource() { | ||
// return DataSourceBuilder.create().type(HikariDataSource.class).build(); | ||
// } | ||
// | ||
// @DependsOn({"masterDataSource", "slaveDataSource"}) | ||
// @Bean | ||
// public DataSource routingDataSource( | ||
// @Qualifier("masterDataSource") DataSource master, | ||
// @Qualifier("slaveDataSource") DataSource slave) { | ||
// DynamicRoutingDataSource routingDataSource = new DynamicRoutingDataSource(); | ||
// | ||
// Map<Object, Object> dataSourceMap = new HashMap<>(); | ||
// | ||
// dataSourceMap.put(MASTER, master); | ||
// dataSourceMap.put(SLAVE, slave); | ||
// | ||
// routingDataSource.setTargetDataSources(dataSourceMap); | ||
// routingDataSource.setDefaultTargetDataSource(master); | ||
// | ||
// return routingDataSource; | ||
// } | ||
// | ||
// @DependsOn({"routingDataSource"}) | ||
// @Bean | ||
// public DataSource dataSource(DataSource routingDataSource) { | ||
// return new LazyConnectionDataSourceProxy(routingDataSource); | ||
// } | ||
// | ||
// @Primary | ||
// @Bean | ||
// public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { | ||
// LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); | ||
// em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); | ||
// em.setDataSource(dataSource); | ||
// em.setPackagesToScan("com.flab.shoeauction.domain"); | ||
// | ||
// Map<String, Object> properties = new HashMap<>(); | ||
// properties.put("hibernate.physical_naming_strategy", | ||
// SpringPhysicalNamingStrategy.class.getName()); | ||
// properties.put("hibernate.implicit_naming_strategy", | ||
// SpringImplicitNamingStrategy.class.getName()); | ||
// properties.put("hibernate.hbm2ddl.auto", env.getProperty("spring.jpa.hibernate.ddl-auto")); | ||
// em.setJpaPropertyMap(properties); | ||
// | ||
// return em; | ||
// } | ||
// | ||
// @Primary | ||
// @Bean | ||
// public PlatformTransactionManager transactionManager( | ||
// EntityManagerFactory entityManagerFactory) { | ||
// JpaTransactionManager transactionManager = new JpaTransactionManager(); | ||
// transactionManager.setEntityManagerFactory(entityManagerFactory); | ||
// | ||
// return transactionManager; | ||
// } | ||
//} | ||
package com.flab.shoeauction.common.config; | ||
|
||
import static com.flab.shoeauction.common.utils.constants.DataSourceConstants.MASTER; | ||
import static com.flab.shoeauction.common.utils.constants.DataSourceConstants.SLAVE; | ||
|
||
import com.flab.shoeauction.common.db.DynamicRoutingDataSource; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.sql.DataSource; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy; | ||
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; | ||
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.core.env.Environment; | ||
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
@EnableTransactionManagement | ||
public class RoutingDataSourceConfig { | ||
|
||
private final Environment env; | ||
|
||
@ConfigurationProperties(prefix = "spring.datasource.hikari.master") | ||
@Bean | ||
public DataSource masterDataSource() { | ||
return DataSourceBuilder.create().type(HikariDataSource.class).build(); | ||
} | ||
|
||
@ConfigurationProperties(prefix = "spring.datasource.hikari.slave") | ||
@Bean | ||
public DataSource slaveDataSource() { | ||
return DataSourceBuilder.create().type(HikariDataSource.class).build(); | ||
} | ||
|
||
@DependsOn({"masterDataSource", "slaveDataSource"}) | ||
@Bean | ||
public DataSource routingDataSource( | ||
@Qualifier("masterDataSource") DataSource master, | ||
@Qualifier("slaveDataSource") DataSource slave) { | ||
DynamicRoutingDataSource routingDataSource = new DynamicRoutingDataSource(); | ||
|
||
Map<Object, Object> dataSourceMap = new HashMap<>(); | ||
|
||
dataSourceMap.put(MASTER, master); | ||
dataSourceMap.put(SLAVE, slave); | ||
|
||
routingDataSource.setTargetDataSources(dataSourceMap); | ||
routingDataSource.setDefaultTargetDataSource(master); | ||
|
||
return routingDataSource; | ||
} | ||
|
||
@DependsOn({"routingDataSource"}) | ||
@Bean | ||
public DataSource dataSource(DataSource routingDataSource) { | ||
return new LazyConnectionDataSourceProxy(routingDataSource); | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { | ||
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); | ||
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); | ||
em.setDataSource(dataSource); | ||
em.setPackagesToScan("com.flab.shoeauction.domain"); | ||
|
||
Map<String, Object> properties = new HashMap<>(); | ||
properties.put("hibernate.physical_naming_strategy", | ||
SpringPhysicalNamingStrategy.class.getName()); | ||
properties.put("hibernate.implicit_naming_strategy", | ||
SpringImplicitNamingStrategy.class.getName()); | ||
properties.put("hibernate.hbm2ddl.auto", env.getProperty("spring.jpa.hibernate.ddl-auto")); | ||
em.setJpaPropertyMap(properties); | ||
|
||
return em; | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public PlatformTransactionManager transactionManager( | ||
EntityManagerFactory entityManagerFactory) { | ||
JpaTransactionManager transactionManager = new JpaTransactionManager(); | ||
transactionManager.setEntityManagerFactory(entityManagerFactory); | ||
|
||
return transactionManager; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/com/flab/shoeauction/controller/AdminApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters