-
Spring Framework 3.x 이하에서 CGLIB proxy 사용 시 에러Spring Framework 2019. 9. 20. 13:50
Spring AOP는 대상 객체를 프록시하기 위해 내부적으로 JDK dynamic proxy 또는 CGLIB를 사용한다.
대상이 최소 하나의 인터페이스를 구현한 객체라면 JDK dynamic proxy를 사용하고, 인터페이스를 구현하지 않은 객체라면 CGLIB proxy가 생성된다.
Spring Framework 3.x 이하에서 CGLIB 사용 시 대상 객체가 constructor injection을 사용한다면 아래와 같은 에러가 발생한다.
Could not generate CGLIB subclass of class: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
대상 객체가 default constructor를 가져야한다는 말인데, Create CGLIB proxy instances honoring <constructor-arg> tags [SPR-3150]를 확인해보면 Spring Framework 4.0부터 Objenesis library를 사용한 ObjenesisCglibAopProxy를 통해 default constructor를 호출하지 않고도 인스턴스를 생성할 수 있도록 한 것으로 보인다.
필자는 4.x대로 버전업을 하기 힘든 상황이었기 때문에 DI 방식을 field injection으로 대체하였다.
'Spring Framework' 카테고리의 다른 글
Spring MVC Controller에서 transaction이 적용되지 않는다. (Self-Invocation) (0) 2019.10.11