|
|
|
|
@ -7,7 +7,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
|
import org.springframework.transaction.TransactionDefinition;
|
|
|
|
|
import org.springframework.transaction.interceptor.*;
|
|
|
|
|
|
|
|
|
|
@ -17,79 +17,58 @@ import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ClassName : EgovConfigAppTransaction.java
|
|
|
|
|
* @ClassName : EgovConfigTransaction.java
|
|
|
|
|
* @Description : Transaction 설정
|
|
|
|
|
*
|
|
|
|
|
* @author : 윤주호
|
|
|
|
|
* @since : 2021. 7. 20
|
|
|
|
|
* @version : 1.0
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* << 개정이력(Modification Information) >>
|
|
|
|
|
*
|
|
|
|
|
* 수정일 수정자 수정내용
|
|
|
|
|
* ------------- ------------ ---------------------
|
|
|
|
|
* 2021. 7. 20 윤주호 최초 생성
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Configuration
|
|
|
|
|
public class EgovConfigTransaction {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
DataSource dataSource;
|
|
|
|
|
@Autowired
|
|
|
|
|
DataSource dataSource;
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void init() {
|
|
|
|
|
log.info("Datasource type: {}", dataSource.getClass().getName());
|
|
|
|
|
}
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void init() {
|
|
|
|
|
log.info("Datasource type: {}", dataSource.getClass().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public DataSourceTransactionManager txManager() {
|
|
|
|
|
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
|
|
|
|
|
dataSourceTransactionManager.setDataSource(dataSource);
|
|
|
|
|
return dataSourceTransactionManager;
|
|
|
|
|
}
|
|
|
|
|
// ✅ 더 이상 DataSourceTransactionManager 직접 생성 X
|
|
|
|
|
// JPAConfig 에서 만든 "transactionManager" (JpaTransactionManager)를 주입받아 사용
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------
|
|
|
|
|
// TransactionAdvice 설정
|
|
|
|
|
// -------------------------------------------------------------
|
|
|
|
|
@Bean
|
|
|
|
|
public TransactionInterceptor txAdvice(PlatformTransactionManager transactionManager) {
|
|
|
|
|
TransactionInterceptor txAdvice = new TransactionInterceptor();
|
|
|
|
|
txAdvice.setTransactionManager(transactionManager);
|
|
|
|
|
txAdvice.setTransactionAttributeSource(getNameMatchTransactionAttributeSource());
|
|
|
|
|
return txAdvice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public TransactionInterceptor txAdvice(DataSourceTransactionManager txManager) {
|
|
|
|
|
TransactionInterceptor txAdvice = new TransactionInterceptor();
|
|
|
|
|
txAdvice.setTransactionManager(txManager);
|
|
|
|
|
txAdvice.setTransactionAttributeSource(getNameMatchTransactionAttributeSource());
|
|
|
|
|
return txAdvice;
|
|
|
|
|
}
|
|
|
|
|
private NameMatchTransactionAttributeSource getNameMatchTransactionAttributeSource() {
|
|
|
|
|
NameMatchTransactionAttributeSource txAttributeSource = new NameMatchTransactionAttributeSource();
|
|
|
|
|
txAttributeSource.setNameMap(getRuleBasedTxAttributeMap());
|
|
|
|
|
return txAttributeSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NameMatchTransactionAttributeSource getNameMatchTransactionAttributeSource() {
|
|
|
|
|
NameMatchTransactionAttributeSource txAttributeSource = new NameMatchTransactionAttributeSource();
|
|
|
|
|
txAttributeSource.setNameMap(getRuleBasedTxAttributeMap());
|
|
|
|
|
return txAttributeSource;
|
|
|
|
|
}
|
|
|
|
|
private HashMap<String, TransactionAttribute> getRuleBasedTxAttributeMap() {
|
|
|
|
|
HashMap<String, TransactionAttribute> txMethods = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private HashMap<String, TransactionAttribute> getRuleBasedTxAttributeMap() {
|
|
|
|
|
HashMap<String, TransactionAttribute> txMethods = new HashMap<String, TransactionAttribute>();
|
|
|
|
|
RuleBasedTransactionAttribute txAttribute = new RuleBasedTransactionAttribute();
|
|
|
|
|
txAttribute.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
|
|
|
|
txAttribute.setRollbackRules(Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
|
|
|
|
|
|
|
|
|
|
RuleBasedTransactionAttribute txAttribute = new RuleBasedTransactionAttribute();
|
|
|
|
|
txAttribute.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
|
|
|
|
txAttribute.setRollbackRules(Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
|
|
|
|
|
txMethods.put("*", txAttribute);
|
|
|
|
|
// 이름 패턴별 트랜잭션 속성 설정
|
|
|
|
|
// 여기서는 모든 메서드에 동일 룰 적용
|
|
|
|
|
txMethods.put("*", txAttribute);
|
|
|
|
|
|
|
|
|
|
return txMethods;
|
|
|
|
|
}
|
|
|
|
|
return txMethods;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------
|
|
|
|
|
// TransactionAdvisor 설정
|
|
|
|
|
// -------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public Advisor txAdvisor(DataSourceTransactionManager txManager) {
|
|
|
|
|
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
|
|
|
|
pointcut.setExpression(
|
|
|
|
|
"execution(* go.kr.project..impl.*Impl.*(..)) or execution(* egovframework.com..*Impl.*(..))");
|
|
|
|
|
return new DefaultPointcutAdvisor(pointcut, txAdvice(txManager));
|
|
|
|
|
}
|
|
|
|
|
@Bean
|
|
|
|
|
public Advisor txAdvisor(PlatformTransactionManager transactionManager) {
|
|
|
|
|
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
|
|
|
|
pointcut.setExpression(
|
|
|
|
|
"execution(* go.kr.project..impl.*Impl.*(..)) or execution(* egovframework.com..*Impl.*(..))"
|
|
|
|
|
);
|
|
|
|
|
return new DefaultPointcutAdvisor(pointcut, txAdvice(transactionManager));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|