본문 바로가기

프로그래밍/Java

Eclipse에서 Lombok 과 MapStruct 사용

728x90
반응형

java bean mapping framework 중 MapStruct가 가장 우수합니다.

ModleMapper의 경우 reflection-based라서 성능 상에 이슈가 있으므로 MapStruct를 추천합니다.

 
MapStruct is definitely more efficient than any reflection-based approach. Plain method invocations done in the generated code is as fast as it gets. Huge runtime overhead of a reflection-based mapping tool (not BeanUtils, another one) was one of the motivators for writing it. Also you get quick feedback right in your IDE on wrong or incomplete mappings (try our Eclipse plug-in for some more goodies such as code completion in @Mapping annotations). Plus, the generated code has no runtime dependencies, which e.g. makes it nice for Android and similar embedded usage.

 

Performance of Java Mapping Frameworks : https://www.baeldung.com/java-performance-mapping-frameworks

 

Performance of Java Mapping Frameworks | Baeldung

MapStruct comes out on top, followed by JMapper as a close second. The other libraries follow far behind: Orika, ModelMapper, and Dozer.

www.baeldung.com

Quick Guide to MapStruct : www.baeldung.com/mapstruct

 

Quick Guide to MapStruct | Baeldung

A quick and practical guide to using MapStruct

www.baeldung.com

MapStruct Eclipse Plugin : marketplace.eclipse.org/content/mapstruct-eclipse-plugin

 

MapStruct Eclipse Plugin

An Eclipse plug-in for working with MapStruct The plugin gives some assistence in projects that use MapStruct to generate bean mapping code. Code-Completions Completion of target and source properties in @Mapping annotation for bean mappings and for enum m

marketplace.eclipse.org

Eclipse STS에서 Lombok 과 MapStruct 를 같이 사용할 경우 Annotation Processing 설정이 필요한데 아래 사항을 참고하시길 바랍니다.

 

  • https://github.com/mapstruct/mapstruct/issues/1159
    • Our current workaround: add the org.mapstruct.ap.spi.AstModifyingAnnotationProcessor.class file to the lombok.jar supplied to eclipse. Not pretty, but is works (for now).

    • STS가 로딩시 agent로 기동하는 lombok.jar 에 위 mapstruct의 class file 을 추가합니다. (gradle 에서 받는 lombok.jar는 교체할 필요가 없습니다.)
    • 위 작업 후 STS를 재기동합니다.
  • 프로젝트 속성의 Annotation Processing에 체크 및 Factory Path를 설정합니다. (lombok 버전은 상관없습니다.)

  • Add External JARs 로 아래와 같이 설정

  • clean 하면 자동 리빌드가 진행되고 아래 경로에 자동으로 코드가 생성되면 셋팅 정상

#lombok #mapstruct #eclipse #java #mapper #modelmapper #annotation

728x90
반응형