MapStruct implementation is not working in Spring Boot Web Application

前端 未结 5 1707
醉话见心
醉话见心 2021-02-06 13:07

I am a newbie to Spring Boot and MapStruct Tool.

Earlier, A Project(written by other team using these technologies) is not starting up. Then, I had made some changes i

5条回答
  •  [愿得一人]
    2021-02-06 13:43

    First of all, public UserAndEmployeeMapper INSTANCE = Mappers.getMapper( UserAndEmployeeMapper.class ); should only be used with the default component model, otherwise you risk to have the UserAndEmployeeMapper not correctly initialized.

    The UserAndEmployeeMapper in your LoginServiceImpl must be annotated with @Autowired, otherwise it cannot be injected by Spring, and that's why it is null.

    I don't know your package structure. If your Spring Boot application class in the package org then it will pick up the UserAndEmployeeMapperImpl. Otherwise make sure that the spring configuration picks up the UserAndEmployeeMapperImpl.

    If everything from above is correctly setup and you are starting the application via an IDE make sure that target/generated-sources or the alternative for Gradle is part of your sources and is picked up. Have a look at the IDE Support to make sure that you have correctly setup the Annotation processor discovery for an IDE. For example, IntelliJ will not invoke the MapStruct Annotation Processor with your current setup, it doesn't pick up the annotationProcessorPaths from the maven compiler.

提交回复
热议问题