fix: TransactionManager Bean 충돌 해결 (egovframework 기본 설정 사용)
DatabaseConfig에서 중복 TransactionManager Bean 제거 ## 문제 - DatabaseConfig.transactionManager와 EgovConfigTransaction.txManager 충돌 - "expected single matching bean but found 2" 에러 발생 ## 해결 - DatabaseConfig에서 transactionManager Bean 제거 - egovframework의 txManager Bean 사용 - DatabaseConfig는 MapperScan만 담당 ## 최종 설정 - DataSource: egovframework.config.DataSourceProxyConfig - TransactionManager: egovframework.config.EgovConfigTransaction.txManager - MapperScan: DatabaseConfig 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>internalApi
parent
c8bf89b2e7
commit
8757eb9e95
@ -1,57 +1,21 @@
|
|||||||
package go.kr.project.api.config;
|
package go.kr.project.api.config;
|
||||||
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
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.annotation.EnableTransactionManagement;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 데이터베이스 및 트랜잭션 설정
|
* MyBatis Mapper 스캔 설정
|
||||||
*
|
*
|
||||||
* <p>이 클래스는 데이터베이스 연결과 트랜잭션 관리를 위한 설정을 제공합니다.
|
* <p>이 클래스는 MyBatis Mapper 인터페이스 스캔을 위한 설정을 제공합니다.</p>
|
||||||
* Spring Boot의 자동 설정을 활용하되, 명시적인 트랜잭션 관리를 위해
|
|
||||||
* TransactionManager를 직접 설정합니다.</p>
|
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>DataSource: application.yml에서 자동 설정</li>
|
* <li>DataSource: egovframework 기본 설정 사용 (DataSourceProxyConfig)</li>
|
||||||
|
* <li>TransactionManager: egovframework 기본 설정 사용 (EgovConfigTransaction.txManager)</li>
|
||||||
* <li>SqlSessionFactory: MyBatis Spring Boot Starter가 자동 생성</li>
|
* <li>SqlSessionFactory: MyBatis Spring Boot Starter가 자동 생성</li>
|
||||||
* <li>TransactionManager: 명시적으로 설정하여 트랜잭션 관리</li>
|
* <li>MapperScan: go.kr.project 및 egovframework 하위 mapper 패키지 자동 스캔</li>
|
||||||
* <li>MapperScan: go.kr.project 하위 mapper 패키지 자동 스캔</li>
|
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableTransactionManagement
|
|
||||||
@MapperScan({"go.kr.project.api.internal.mapper", "go.kr.project.**.mapper", "egovframework.**.mapper"})
|
@MapperScan({"go.kr.project.api.internal.mapper", "go.kr.project.**.mapper", "egovframework.**.mapper"})
|
||||||
public class DatabaseConfig {
|
public class DatabaseConfig {
|
||||||
|
|
||||||
/**
|
|
||||||
* 트랜잭션 관리자를 설정합니다.
|
|
||||||
*
|
|
||||||
* <p>DataSourceTransactionManager는 JDBC 기반의 트랜잭션을 관리합니다.
|
|
||||||
* @Transactional 어노테이션을 사용하여 선언적 트랜잭션 관리가 가능합니다.</p>
|
|
||||||
*
|
|
||||||
* <p>트랜잭션 전파(Propagation), 격리 수준(Isolation), 타임아웃 등의
|
|
||||||
* 세부 설정은 @Transactional 어노테이션의 속성으로 지정할 수 있습니다.</p>
|
|
||||||
*
|
|
||||||
* <p>예제:</p>
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
|
|
||||||
* public void saveData() {
|
|
||||||
* // 트랜잭션 처리가 필요한 로직
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @param dataSource Spring Boot가 자동 생성한 DataSource 빈
|
|
||||||
* @return PlatformTransactionManager 트랜잭션 관리자 인스턴스
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public PlatformTransactionManager transactionManager(DataSource dataSource) {
|
|
||||||
return new DataSourceTransactionManager(dataSource);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue