feat: DataSource properties에 database 추가

-> mybatis xml 이름 정의
         ens-${database}-mapper.xml 형태로 정의
      batch scheduler cronjob 적용
dev
gitea-관리자 1 year ago
parent 0d5d5ece4e
commit f7810a69a1

@ -5,13 +5,17 @@ spring:
datasource: datasource:
hikari: hikari:
# 9 server # 9 server
maria: primary:
database: mysql
driver-class-name: org.mariadb.jdbc.Driver driver-class-name: org.mariadb.jdbc.Driver
jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true
username: root username: root
password: xit1807 password: xit1807
read-only: false read-only: false
# multi-database
#secondary:
devtools: devtools:
livereload: livereload:
enabled: true enabled: true

@ -6,11 +6,14 @@ spring:
hikari: hikari:
# 9 server # 9 server
primary: primary:
database: mysql
driver-class-name: org.mariadb.jdbc.Driver driver-class-name: org.mariadb.jdbc.Driver
jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true
username: root username: root
password: xit1807 password: xit1807
read-only: false read-only: false
# multi-database
#secondary:
devtools: devtools:
restart: restart:

@ -6,12 +6,15 @@ spring:
hikari: hikari:
# 9 server # 9 server
primary: primary:
database: mysql
driver-class-name: org.mariadb.jdbc.Driver driver-class-name: org.mariadb.jdbc.Driver
# jdbc:mariadb://127.0.0.1:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true # jdbc:mariadb://127.0.0.1:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true
jdbc-url: ENC(N7TRplIpBBUbXtSi8fx0wr92OdMgvp9Iw5tmaW7EUaH6ialiAWohx+rOEZx/j+OHFkJSrhYQElPIVe5r4d0tWDNREpgvKwxZRTGXhNdTMMUUHonkGKfB7bURxMfjuMSQEUdKicPZv+xB9eGlwcuPpgC7vaQuZM6WrUDP31+6qYboTUQKBK/7lg==) jdbc-url: ENC(N7TRplIpBBUbXtSi8fx0wr92OdMgvp9Iw5tmaW7EUaH6ialiAWohx+rOEZx/j+OHFkJSrhYQElPIVe5r4d0tWDNREpgvKwxZRTGXhNdTMMUUHonkGKfB7bURxMfjuMSQEUdKicPZv+xB9eGlwcuPpgC7vaQuZM6WrUDP31+6qYboTUQKBK/7lg==)
username: ENC(wgnjrc4VB7R3I+OwMV+iXQ==) username: ENC(wgnjrc4VB7R3I+OwMV+iXQ==)
password: ENC(+sXCmhmSV3Q/3KgOnmpnTQ==) password: ENC(+sXCmhmSV3Q/3KgOnmpnTQ==)
read-only: false read-only: false
# multi-database
#secondary:
devtools: devtools:
livereload: livereload:

@ -15,6 +15,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@ -45,7 +46,7 @@ public class SndngCloseJobScheduler {
@Value("${app.slack-webhook.enabled:false}") @Value("${app.slack-webhook.enabled:false}")
private String isSlackEnabled; private String isSlackEnabled;
//@Scheduled(cron = "${app.batch.cron.ens.close}") @Scheduled(cron = "${app.batch.cron.ens.close}")
public void runJob() { public void runJob() {
Map<String, JobParameter> confMap = new HashMap<>(); Map<String, JobParameter> confMap = new HashMap<>();

@ -15,6 +15,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@ -45,7 +46,7 @@ public class SndngMakeJobScheduler {
@Value("${app.slack-webhook.enabled:false}") @Value("${app.slack-webhook.enabled:false}")
private String isSlackEnabled; private String isSlackEnabled;
//@Scheduled(cron = "${app.batch.cron.ens.make}") @Scheduled(cron = "${app.batch.cron.ens.make}")
public void runJob() { public void runJob() {
Map<String, JobParameter> confMap = new HashMap<>(); Map<String, JobParameter> confMap = new HashMap<>();

@ -15,6 +15,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@ -44,7 +45,7 @@ public class SndngSendBulksJobScheduler {
@Value("${app.slack-webhook.enabled:false}") @Value("${app.slack-webhook.enabled:false}")
private String isSlackEnabled; private String isSlackEnabled;
//@Scheduled(cron = "${app.batch.cron.ens.send}") @Scheduled(cron = "${app.batch.cron.ens.send}")
public void runJob() { public void runJob() {
Map<String, JobParameter> confMap = new HashMap<>(); Map<String, JobParameter> confMap = new HashMap<>();

@ -15,6 +15,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@ -44,7 +45,7 @@ public class SndngStatusBulksJobScheduler {
@Value("${app.slack-webhook.enabled:false}") @Value("${app.slack-webhook.enabled:false}")
private String isSlackEnabled; private String isSlackEnabled;
//@Scheduled(cron = "${app.batch.cron.ens.kko-status}") @Scheduled(cron = "${app.batch.cron.ens.kko-status}")
public void runJob() { public void runJob() {
Map<String, JobParameter> confMap = new HashMap<>(); Map<String, JobParameter> confMap = new HashMap<>();

@ -10,16 +10,16 @@ spring:
hikari: hikari:
# 9 server # 9 server
maria: maria:
database: mysql
driver-class-name: org.mariadb.jdbc.Driver driver-class-name: org.mariadb.jdbc.Driver
jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true
username: root username: root
password: xit1807 password: xit1807
read-only: false read-only: false
# 115 server # multi-database
# jdbc:oracle:thin:@211.119.124.115:1521:XITSMS # secondary:
# xit_sms_lg / xit_sms_lg # database: oracle
# oracle:
# driver-class-name: oracle.jdbc.OracleDriver # driver-class-name: oracle.jdbc.OracleDriver
# jdbc-url: jdbc:oracle:thin:@211.119.124.115:1521:XITSMS # jdbc-url: jdbc:oracle:thin:@211.119.124.115:1521:XITSMS
# username: xit_sms_lg # username: xit_sms_lg

@ -10,12 +10,16 @@ spring:
hikari: hikari:
# 9 server # 9 server
primary: primary:
database: mysql
driver-class-name: org.mariadb.jdbc.Driver driver-class-name: org.mariadb.jdbc.Driver
jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true jdbc-url: jdbc:mariadb://211.119.124.9:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true
username: root username: root
password: xit1807 password: xit1807
read-only: false read-only: false
# multi-database
#secondary:
# 115 server # 115 server
# jdbc:oracle:thin:@211.119.124.115:1521:XITSMS # jdbc:oracle:thin:@211.119.124.115:1521:XITSMS
# xit_sms_lg / xit_sms_lg # xit_sms_lg / xit_sms_lg

@ -8,6 +8,7 @@ spring:
hikari: hikari:
# 9 server # 9 server
primary: primary:
database: mysql
driver-class-name: org.mariadb.jdbc.Driver driver-class-name: org.mariadb.jdbc.Driver
# jdbc:mariadb://127.0.0.1:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true # jdbc:mariadb://127.0.0.1:4407/mens?useUnicode=true&characterEncoding=utf-8&rewriteBatchedStatements=true&autoReconnect=true
jdbc-url: ENC(N7TRplIpBBUbXtSi8fx0wr92OdMgvp9Iw5tmaW7EUaH6ialiAWohx+rOEZx/j+OHFkJSrhYQElPIVe5r4d0tWDNREpgvKwxZRTGXhNdTMMUUHonkGKfB7bURxMfjuMSQEUdKicPZv+xB9eGlwcuPpgC7vaQuZM6WrUDP31+6qYboTUQKBK/7lg==) jdbc-url: ENC(N7TRplIpBBUbXtSi8fx0wr92OdMgvp9Iw5tmaW7EUaH6ialiAWohx+rOEZx/j+OHFkJSrhYQElPIVe5r4d0tWDNREpgvKwxZRTGXhNdTMMUUHonkGKfB7bURxMfjuMSQEUdKicPZv+xB9eGlwcuPpgC7vaQuZM6WrUDP31+6qYboTUQKBK/7lg==)
@ -15,6 +16,9 @@ spring:
password: ENC(+sXCmhmSV3Q/3KgOnmpnTQ==) password: ENC(+sXCmhmSV3Q/3KgOnmpnTQ==)
read-only: false read-only: false
# multi-database
#secondary:
devtools: devtools:
livereload: livereload:
enabled: false enabled: false

@ -7,6 +7,7 @@ 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.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -44,8 +45,9 @@ import org.springframework.jdbc.support.lob.DefaultLobHandler;
sqlSessionFactoryRef = Constants.PRIMARY_SQL_SESSION sqlSessionFactoryRef = Constants.PRIMARY_SQL_SESSION
) )
public class PrimaryMybatisConfig { public class PrimaryMybatisConfig {
@Value("${spring.datasource.hikari.primary.database}")
static final String MYBATIS_CONFIG_FILE = "classpath:/egovframework/mapper/mapper-config.xml"; private String database;
private static final String MYBATIS_CONFIG_FILE = "classpath:/egovframework/mapper/mapper-config.xml";
@ConditionalOnMissingBean @ConditionalOnMissingBean
@Bean @Bean
@ -61,7 +63,7 @@ public class PrimaryMybatisConfig {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource); sessionFactory.setDataSource(dataSource);
sessionFactory.setConfigLocation(resolver.getResource(MYBATIS_CONFIG_FILE)); sessionFactory.setConfigLocation(resolver.getResource(MYBATIS_CONFIG_FILE));
sessionFactory.setMapperLocations(resolver.getResources("classpath:/egovframework/mapper/**/*-mysql-mapper.xml")); sessionFactory.setMapperLocations(resolver.getResources(String.format("classpath:/egovframework/mapper/**/*-%s-mapper.xml", database)));
return sessionFactory.getObject(); return sessionFactory.getObject();
} }

@ -7,6 +7,7 @@ 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.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 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;
@ -36,7 +37,9 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
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"; @Value("${spring.datasource.hikari.secondary.database}")
private String database;
private static final String MYBATIS_CONFIG_FILE = "classpath:/egovframework/mapper/mapper-config.xml";
@Bean(name = Constants.SECONDARY_SQL_SESSION) @Bean(name = Constants.SECONDARY_SQL_SESSION)
public SqlSessionFactory secondarySqlSession(@Qualifier(Constants.SECONDARY_DATA_SOURCE) DataSource dataSource) throws Exception { public SqlSessionFactory secondarySqlSession(@Qualifier(Constants.SECONDARY_DATA_SOURCE) DataSource dataSource) throws Exception {
@ -44,7 +47,7 @@ public class SecondaryMybatisConfig {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource); sessionFactory.setDataSource(dataSource);
sessionFactory.setConfigLocation(resolver.getResource(MYBATIS_CONFIG_FILE)); sessionFactory.setConfigLocation(resolver.getResource(MYBATIS_CONFIG_FILE));
sessionFactory.setMapperLocations(resolver.getResources("classpath:/egovframework/mapper/**/*-oracle-mapper.xml")); sessionFactory.setMapperLocations(resolver.getResources(String.format("classpath:/egovframework/mapper/**/*-%s-mapper.xml", database)));
return sessionFactory.getObject(); return sessionFactory.getObject();
} }

Loading…
Cancel
Save