feat: DB dynamic 설정 batch에서 mens-core 로 이동
parent
1361549b20
commit
cec6ad5d37
@ -1,58 +0,0 @@
|
|||||||
package kr.xit.core.spring.config.support;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
import kr.xit.core.consts.Constants;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
//FIXME :: 재설정이 필요한 경우 해당 프로젝트에 동일한 파일로 재정의 하여 사용
|
|
||||||
/**
|
|
||||||
* <pre>
|
|
||||||
* description : Datasource 설정 - FIXME:: spring.datasource 설정이 있는 경우만 loading
|
|
||||||
* - 조건 : spring.datasource
|
|
||||||
* 실제 필요한 경우만 커넥션을 점유하도록
|
|
||||||
* LazyConnectionDataSourceProxy 사용
|
|
||||||
* 일반 Datasource 사용시
|
|
||||||
* - Spring은 트랜잭션에 진입시 데이타 소스의 커넥션을 get
|
|
||||||
* - ehcache, hibernate 영속성 컨택슽트 1차캐시 등에도 커넥션을 get
|
|
||||||
* - multi-datasource 에서 트랜잭션 진입 이후 datasource 분기 불가
|
|
||||||
* packageName : kr.xit.core.spring.config.support
|
|
||||||
* fileName : DatasourceConfig
|
|
||||||
* author : julim
|
|
||||||
* date : 2023-04-28
|
|
||||||
* ======================================================================
|
|
||||||
* 변경일 변경자 변경 내용
|
|
||||||
* ----------------------------------------------------------------------
|
|
||||||
* 2023-04-28 julim 최초 생성
|
|
||||||
*
|
|
||||||
* </pre>
|
|
||||||
* @see PrimaryMybatisConfig
|
|
||||||
*/
|
|
||||||
//@ConditionalOnProperty(value = "spring", havingValue = "datasource", matchIfMissing = false)
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
public class DatasourceConfig {
|
|
||||||
@Bean(name = "primaryHikariConfig")
|
|
||||||
@Primary
|
|
||||||
@ConfigurationProperties(prefix = "spring.datasource.hikari.primary")
|
|
||||||
public HikariConfig primaryHikariConfig() {
|
|
||||||
// HikariConfig hikariConfig = new HikariConfig("spring.datasource.hikari");
|
|
||||||
// hikariConfig.setAutoCommit(false);
|
|
||||||
// return hikariConfig;
|
|
||||||
return new HikariConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(Constants.PRIMARY_DATA_SOURCE)
|
|
||||||
@Primary
|
|
||||||
public DataSource primaryDataSource() throws Exception{
|
|
||||||
//return new LazyConnectionDataSourceProxy(new HikariDataSource(primaryHikariConfig()));
|
|
||||||
return new HikariDataSource(primaryHikariConfig());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
package kr.xit.core.spring.config.support;
|
|
||||||
|
|
||||||
import kr.xit.core.consts.Constants;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
|
||||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
|
||||||
import org.mybatis.spring.SqlSessionTemplate;
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.context.annotation.*;
|
|
||||||
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 :: 재설정이 필요한 경우 해당프로젝트에 동일한 파일로 재정의 하여 사용
|
|
||||||
/**
|
|
||||||
* <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
|
|
||||||
@MapperScan(
|
|
||||||
basePackages = {
|
|
||||||
"kr.xit.core.**.mapper",
|
|
||||||
"kr.xit.biz.**.mapper",
|
|
||||||
"kr.xit.ens.**.mapper",
|
|
||||||
},
|
|
||||||
sqlSessionFactoryRef = Constants.PRIMARY_SQL_SESSION
|
|
||||||
)
|
|
||||||
public class PrimaryMybatisConfig {
|
|
||||||
|
|
||||||
static final String MYBATIS_CONFIG_FILE = "classpath:/egovframework/mapper/mapper-config.xml";
|
|
||||||
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
@Bean
|
|
||||||
@Lazy
|
|
||||||
public DefaultLobHandler lobHandler() {
|
|
||||||
return new DefaultLobHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Primary
|
|
||||||
@Bean(name = Constants.PRIMARY_SQL_SESSION)
|
|
||||||
public SqlSessionFactory primarySqlSession(@Qualifier(Constants.PRIMARY_DATA_SOURCE)DataSource dataSource) throws Exception {
|
|
||||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
|
||||||
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
|
||||||
sessionFactory.setDataSource(dataSource);
|
|
||||||
sessionFactory.setConfigLocation(resolver.getResource(MYBATIS_CONFIG_FILE));
|
|
||||||
sessionFactory.setMapperLocations(resolver.getResources("classpath:/egovframework/mapper/**/*-mysql-mapper.xml"));
|
|
||||||
return sessionFactory.getObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Primary
|
|
||||||
@Bean(name = "primarySqlSessionTemplate")
|
|
||||||
public SqlSessionTemplate primarySqlSessionTemplate(@Qualifier(Constants.PRIMARY_SQL_SESSION) SqlSessionFactory sqlSessionFactory) {
|
|
||||||
return new SqlSessionTemplate(sqlSessionFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Primary
|
|
||||||
@Bean
|
|
||||||
public PlatformTransactionManager primaryTransactionManager(@Qualifier(Constants.PRIMARY_DATA_SOURCE)DataSource dataSource) {
|
|
||||||
DataSourceTransactionManager dstm = new DataSourceTransactionManager(dataSource);
|
|
||||||
dstm.setGlobalRollbackOnParticipationFailure(false);
|
|
||||||
return dstm;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue