diff --git a/src/main/java/egovframework/config/EgovConfigTransaction.java b/src/main/java/egovframework/config/EgovConfigTransaction.java
index 6d8836d..1fc2a1d 100644
--- a/src/main/java/egovframework/config/EgovConfigTransaction.java
+++ b/src/main/java/egovframework/config/EgovConfigTransaction.java
@@ -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
- *
- *
- * << 개정이력(Modification Information) >>
- *
- * 수정일 수정자 수정내용
- * ------------- ------------ ---------------------
- * 2021. 7. 20 윤주호 최초 생성
- *
- *
*/
@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 getRuleBasedTxAttributeMap() {
+ HashMap txMethods = new HashMap<>();
- private HashMap getRuleBasedTxAttributeMap() {
- HashMap txMethods = new HashMap();
+ 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));
+ }
}
diff --git a/src/main/java/egovframework/config/JPAConf/JPAConfig.java b/src/main/java/egovframework/config/JPAConf/JPAConfig.java
index d4b7aba..1635a7f 100644
--- a/src/main/java/egovframework/config/JPAConf/JPAConfig.java
+++ b/src/main/java/egovframework/config/JPAConf/JPAConfig.java
@@ -3,9 +3,8 @@ package egovframework.config.JPAConf;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
import org.springframework.orm.jpa.JpaTransactionManager;
-import org.springframework.orm.jpa.JpaVendorAdapter;
-import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -17,22 +16,28 @@ public class JPAConfig {
@PersistenceContext
private EntityManager em;
+ /** QueryDSL용 JPAQueryFactory */
@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(em);
}
+ /**
+ * 기본 트랜잭션 매니저
+ */
@Bean(name = "transactionManager")
+ @Primary
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
-// @Bean
-// public JpaVendorAdapter jpaVendorAdapter() {
-// HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
-// adapter.setShowSql(false);
-// adapter.setGenerateDdl(false);
-// adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
-// return adapter;
-// }
+ // 필요하면 나중에 다시 켜서 쓰면 됨
+ // @Bean
+ // public JpaVendorAdapter jpaVendorAdapter() {
+ // HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
+ // adapter.setShowSql(false);
+ // adapter.setGenerateDdl(false);
+ // adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
+ // return adapter;
+ // }
}