mapstruct / mapstruct-examples

Examples for using MapStruct
Other
1.28k stars 511 forks source link

How to using mapstruct and springboot bean together? #130

Closed daidai21 closed 2 years ago

daidai21 commented 2 years ago
@Mapper(componentModel = "spring")
public interface DemoConvert {
    public static DemoConvert INSTANCE = mappers.getMapper(DemoConvert.class);

    @AutoWired
    private PersonInfoSearchService personInfoSearchService;

    @Mapping(source = "id", target = "id")
    @Mapping(source = "id", target = "gender", expression = "java(personInfoSearchService.searchGenderById(id))")
    PersonDTO toPerson(TeacherDTO teacherDTO);
}

This demo result is AutoWired is not working. How to solve it?

tks!

filiphr commented 2 years ago

Please do not use the issue tracker for asking questions. If you need to ask question you can use StackOverflow or ask in our Gitter room.

The code you have shared does not even compile.