fix(common): EncryptTypeHandler 를 Spring 빈에서 분리
mybatis-spring-boot-starter 가 BaseTypeHandler<String> 빈을 자동 등록하면서 모든 String 컬럼에 적용해버리는 문제 해결. @Component 를 제거하고 EncryptTypeHandlerInitializer (@Configuration) 에서 EncryptUtil 만 정적 주입. 사용처는 mapper XML 에서 컬럼별 typeHandler 속성으로 명시(기존과 동일). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,10 +3,6 @@ package com.ga.common.mybatis;
|
||||
import com.ga.common.util.EncryptUtil;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -16,23 +12,22 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* AES 암호화 컬럼용 TypeHandler.
|
||||
*
|
||||
* @MappedTypes 를 의도적으로 빼서 String 전체 자동 적용을 막는다.
|
||||
* 사용 시 컬럼별로 명시:
|
||||
* 중요: Spring 빈으로 등록하면 mybatis-spring-boot-starter 가 자동으로
|
||||
* 모든 String 컬럼에 적용해 버린다 (BaseTypeHandler<String> 의 generic 때문).
|
||||
* 따라서 @Component 를 붙이지 않고, EncryptUtil 만 정적 주입한다.
|
||||
*
|
||||
* 사용은 컬럼별 명시만 허용:
|
||||
* <result property="residentNo" column="resident_no"
|
||||
* typeHandler="com.ga.common.mybatis.EncryptTypeHandler"/>
|
||||
*
|
||||
* EncryptUtil 주입은 EncryptTypeHandlerInitializer (별도 @Configuration) 에서 수행.
|
||||
*/
|
||||
@Component
|
||||
public class EncryptTypeHandler extends BaseTypeHandler<String> implements ApplicationContextAware {
|
||||
public class EncryptTypeHandler extends BaseTypeHandler<String> {
|
||||
|
||||
private static EncryptUtil encryptUtil;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext ctx) {
|
||||
EncryptTypeHandler.encryptUtil = ctx.getBean(EncryptUtil.class);
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setEncryptUtil(EncryptUtil util) {
|
||||
/** 부팅 시 EncryptTypeHandlerInitializer 가 1회 호출 */
|
||||
public static void setEncryptUtil(EncryptUtil util) {
|
||||
EncryptTypeHandler.encryptUtil = util;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ga.common.mybatis;
|
||||
|
||||
import com.ga.common.util.EncryptUtil;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* EncryptTypeHandler 가 Spring 빈이 아닌 일반 클래스이므로,
|
||||
* 부팅 시 EncryptUtil 인스턴스를 정적으로 주입해주는 초기화 빈.
|
||||
*/
|
||||
@Configuration
|
||||
public class EncryptTypeHandlerInitializer {
|
||||
|
||||
public EncryptTypeHandlerInitializer(EncryptUtil util) {
|
||||
EncryptTypeHandler.setEncryptUtil(util);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user