Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGLIB #2

Closed
Tracked by #1
on-Sync opened this issue Oct 23, 2023 · 0 comments · Fixed by #3, #4 or #5
Closed
Tracked by #1

CGLIB #2

on-Sync opened this issue Oct 23, 2023 · 0 comments · Fixed by #3, #4 or #5
Assignees
Labels

Comments

@on-Sync
Copy link
Contributor

on-Sync commented Oct 23, 2023

cglib 관련 정보

BCI(i.e. ByteCode Instrumentation)를 위한 라이브러리입니다.
BCI 는 .class 에 새로운 코드를 주입하거나 수정하는 기능을 제공합니다.
이는 주로 이는 AOP 를 위한 Weaving 에 사용됩니다.
cglib 은 Runtime Weaving (i.e. RTW) 만 제공하므로 제한적인 join-point 만 사용할 수 있습니다.
이에 대해 cglib 을 채택한 spring-aop 진영에서도 method 실행 시점만 제공하고 있습니다.
spring-aop 는 cglib 외에도 jdk proxy 인 DynamicProxy 를 사용하고 있습니다.
DynamicProxy 는 java api 인 reflection 기반의 동작을 수행하므로 메모리 및 속도에 대한 성능이 좋지 않습니다.
(참고로 DynamicProxy 와 cglib 은 대상이 묵시적인가 명시적인가에 따른 차이점도 존재합니다.)
그렇기에 spring 진영에서는 자체적인 유지보수로 문제가 개선된 cglib 을 spring-boot 의 기본 AOP 툴로 채택하고 있습니다.

java 버전 이슈

cglib 은 2019년 8월에 v3.3.0 를 마지막으로 유지보수가 중단되었습니다.
그렇기에 2021년 9월 출시된 java LTS 인 jdk17 과 호환성 문제가 존재합니다.
이에 대해서 JVM 옵션을 추가하는 것이 소개됩니다.
(e.g. --add-opens java.base/java.lang=ALL-UNNAMED)
제가 해당 방안을 시도했을 때는 문제가 해결되지 않았지만, 관련 이슈에서는 성공한 분들이 계신것으로 보아
JDK 구현체별로 테스트가 필요한 부분인 것 같습니다.

관련이슈 트래킹

cglib

cglib 은 ByteBuddy 를 사용하길 권장하고 있지만, 마이그레이션에 어려움이 존재한다고 합니다.

spring

spring 은 org.springframework:spring-aop 에 자체 cglib 을 직접 유지보수하여 지원하는 것으로 해결방법을 굳혔습니다.
하지만 이는 spring-aop 를 위한 것이지 cglib 을 직접사용하는 것에 대한 기능적 지원은 보장하지 않습니다.

사용해보기

cglib 은 java17 에서 문제가 존재하기에 org.springframework:spring-aop 를 사용하기 바랍니다.

image

cglib 은 주로 모니터링 및 Generated Source 를 위한 도구로 사용되고 있습니다.
이에 대해 대표적으로 ASM 및 Hibernate, ModelMapper 등이 있습니다.

실습참조

@on-Sync on-Sync mentioned this issue Oct 23, 2023
4 tasks
@on-Sync on-Sync linked a pull request Oct 23, 2023 that will close this issue
@on-Sync on-Sync self-assigned this Oct 23, 2023
@on-Sync on-Sync added the aop label Oct 23, 2023
This was linked to pull requests Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant