feat: db분리

dev
gitea-관리자 1 year ago
parent afafd31250
commit 8bc53deddd

@ -2,15 +2,12 @@ package kr.xit.core.spring.config.support;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import kr.xit.core.consts.Constants; import kr.xit.core.consts.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
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.context.annotation.Primary;
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;
import javax.sql.DataSource;
//FIXME :: 재설정이 필요한 경우 해당 프로젝트에 동일한 파일로 재정의 하여 사용 //FIXME :: 재설정이 필요한 경우 해당 프로젝트에 동일한 파일로 재정의 하여 사용
/** /**
@ -36,7 +33,6 @@ import javax.sql.DataSource;
* @see PrimaryMybatisConfig * @see PrimaryMybatisConfig
*/ */
//@ConditionalOnProperty(value = "spring", havingValue = "datasource", matchIfMissing = false) //@ConditionalOnProperty(value = "spring", havingValue = "datasource", matchIfMissing = false)
@Slf4j
@Configuration @Configuration
public class DatasourceConfig { public class DatasourceConfig {
@Bean(name = "primaryHikariConfig") @Bean(name = "primaryHikariConfig")
@ -56,6 +52,7 @@ public class DatasourceConfig {
return new HikariDataSource(primaryHikariConfig()); return new HikariDataSource(primaryHikariConfig());
} }
//@ConditionalOnProperty(value = "spring.datasource.hikari", havingValue = "oracle", matchIfMissing = false)
@Bean(name = "secondaryHikariConfig") @Bean(name = "secondaryHikariConfig")
@ConfigurationProperties(prefix = "spring.datasource.hikari.oracle") @ConfigurationProperties(prefix = "spring.datasource.hikari.oracle")
public HikariConfig secondaryHikariConfig() { public HikariConfig secondaryHikariConfig() {

@ -1,55 +1,31 @@
package kr.xit.core.spring.config.support; package kr.xit.core.spring.config.support;
import javax.sql.DataSource;
import kr.xit.core.consts.Constants; import kr.xit.core.consts.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
//FIXME :: 재설정이 필요한 경우 해당프로젝트에 동일한 파일로 재정의 하여 사용 //FIXME :: 재설정이 필요한 경우 해당프로젝트에 동일한 파일로 재정의 하여 사용
/**
* <pre>
* description : Mybatis - FIXME:: @DependsOn(value = {"dataSource"}) loading
* - : @DependsOn(value = {"dataSource"})
* packageName : kr.xit.core.spring.config.support
* fileName : MybatisConfig
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
* @see DatasourceConfig
*/
@Slf4j
@Configuration @Configuration
@MapperScan( @MapperScan(
basePackages = {"kr.xit.biz.sms.mapper"}, basePackages = {"kr.xit.biz.sms.mapper"},
sqlSessionFactoryRef = Constants.SECONDARY_SQL_SESSION sqlSessionFactoryRef = Constants.SECONDARY_SQL_SESSION
) )
public class SecondaryMybatisConfig { public class SecondaryMybatisConfig {
static final String MYBATIS_CONFIG_FILE = "classpath:/egovframework/mapper/mapper-config.xml"; static final String MYBATIS_CONFIG_FILE = "classpath:/egovframework/mapper/mapper-config.xml";
@Bean(name = Constants.SECONDARY_SQL_SESSION) @ConditionalOnProperty(value = "spring.datasource.hikari", havingValue = "oracle", matchIfMissing = false)
public SqlSessionFactory secondarySqlSession(@Qualifier(Constants.SECONDARY_DATA_SOURCE) DataSource dataSource) throws Exception { public SqlSessionFactory secondarySqlSession(@Qualifier(Constants.SECONDARY_DATA_SOURCE) DataSource dataSource) throws Exception {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
@ -59,6 +35,7 @@ public class SecondaryMybatisConfig {
return sessionFactory.getObject(); return sessionFactory.getObject();
} }
@ConditionalOnProperty(value = "spring.datasource.hikari", havingValue = "oracle", matchIfMissing = false)
@Bean(name = "secondarySqlSessionTemplate") @Bean(name = "secondarySqlSessionTemplate")
public SqlSessionTemplate secondarySqlSessionTemplate(@Qualifier(Constants.SECONDARY_SQL_SESSION) SqlSessionFactory sqlSessionFactory) { public SqlSessionTemplate secondarySqlSessionTemplate(@Qualifier(Constants.SECONDARY_SQL_SESSION) SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory); return new SqlSessionTemplate(sqlSessionFactory);

@ -1,5 +1,6 @@
package kr.xit.core.spring.config.support; package kr.xit.core.spring.config.support;
import javax.sql.DataSource;
import kr.xit.core.consts.Constants; import kr.xit.core.consts.Constants;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -11,8 +12,6 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
//FIXME :: 재설정이 필요한 경우 해당프로젝트에 동일한 파일로 재정의 하여 사용 //FIXME :: 재설정이 필요한 경우 해당프로젝트에 동일한 파일로 재정의 하여 사용
/** /**
@ -35,6 +34,15 @@ import javax.sql.DataSource;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
public class TransactionConfig { public class TransactionConfig {
// @ConditionalOnMissingBean(SecondaryMybatisConfig.class)
// @Primary
// @Bean
// public PlatformTransactionManager primaryTransactionManager(@Qualifier(Constants.PRIMARY_DATA_SOURCE)DataSource dataSource) {
// DataSourceTransactionManager dstm = new DataSourceTransactionManager(dataSource);
// dstm.setGlobalRollbackOnParticipationFailure(false);
// return dstm;
// }
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
// ChainedTransactionManager : trsnsaction binding // ChainedTransactionManager : trsnsaction binding
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -45,6 +53,7 @@ public class TransactionConfig {
* @return PlatformTransactionManager * @return PlatformTransactionManager
* @throws Exception Exception * @throws Exception Exception
*/ */
//@ConditionalOnProperty(value = "spring.datasource.hikari", havingValue = "oracle", matchIfMissing = false)
@Primary @Primary
@Bean @Bean
public PlatformTransactionManager transactionManager(@Qualifier(Constants.PRIMARY_DATA_SOURCE)DataSource mariaDS, public PlatformTransactionManager transactionManager(@Qualifier(Constants.PRIMARY_DATA_SOURCE)DataSource mariaDS,

Loading…
Cancel
Save