From aee9c2c2cac6e646df86685e2f0a229a97569794 Mon Sep 17 00:00:00 2001 From: GA Pro Date: Sun, 10 May 2026 20:39:48 +0900 Subject: [PATCH] =?UTF-8?q?fix(common):=20EncryptTypeHandler=20=EB=A5=BC?= =?UTF-8?q?=20Spring=20=EB=B9=88=EC=97=90=EC=84=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mybatis-spring-boot-starter 가 BaseTypeHandler 빈을 자동 등록하면서 모든 String 컬럼에 적용해버리는 문제 해결. @Component 를 제거하고 EncryptTypeHandlerInitializer (@Configuration) 에서 EncryptUtil 만 정적 주입. 사용처는 mapper XML 에서 컬럼별 typeHandler 속성으로 명시(기존과 동일). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../ga/common/mybatis/EncryptTypeHandler.java | 25 ++++++++----------- .../EncryptTypeHandlerInitializer.java | 16 ++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandlerInitializer.java diff --git a/ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandler.java b/ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandler.java index b59e563..2b7b92f 100644 --- a/ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandler.java +++ b/ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandler.java @@ -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 의 generic 때문). + * 따라서 @Component 를 붙이지 않고, EncryptUtil 만 정적 주입한다. + * + * 사용은 컬럼별 명시만 허용: * + * + * EncryptUtil 주입은 EncryptTypeHandlerInitializer (별도 @Configuration) 에서 수행. */ -@Component -public class EncryptTypeHandler extends BaseTypeHandler implements ApplicationContextAware { +public class EncryptTypeHandler extends BaseTypeHandler { 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; } diff --git a/ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandlerInitializer.java b/ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandlerInitializer.java new file mode 100644 index 0000000..6a19760 --- /dev/null +++ b/ga-common/src/main/java/com/ga/common/mybatis/EncryptTypeHandlerInitializer.java @@ -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); + } +}