Merge branch 'refs/heads/dev' into xithoon

pull/24/head
xhoon 4 weeks ago
commit 46a7008155

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

@ -3,9 +3,8 @@ package egovframework.config.JPAConf;
import com.querydsl.jpa.impl.JPAQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory;
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.orm.jpa.JpaTransactionManager; 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.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
@ -17,22 +16,28 @@ public class JPAConfig {
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
/** QueryDSL용 JPAQueryFactory */
@Bean @Bean
public JPAQueryFactory jpaQueryFactory() { public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(em); return new JPAQueryFactory(em);
} }
/**
*
*/
@Bean(name = "transactionManager") @Bean(name = "transactionManager")
@Primary
public JpaTransactionManager transactionManager(EntityManagerFactory emf) { public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf); return new JpaTransactionManager(emf);
} }
// @Bean // 필요하면 나중에 다시 켜서 쓰면 됨
// public JpaVendorAdapter jpaVendorAdapter() { // @Bean
// HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); // public JpaVendorAdapter jpaVendorAdapter() {
// adapter.setShowSql(false); // HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
// adapter.setGenerateDdl(false); // adapter.setShowSql(false);
// adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect"); // adapter.setGenerateDdl(false);
// return adapter; // adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
// } // return adapter;
// }
} }

Loading…
Cancel
Save