1
votes

I've created some mapstruct mapper annotated with spring constructor injection. I know in the test I can autowire the mapper with springboottest, but it seems very heavy and the loading speed is very slow. Can I get the mapper without initializing the spring context? Is this good practice?

1

1 Answers

1
votes

You can always get a mapper by means of Mappers.getMapper(MapperClass.class). However, the problem arises when that mapper uses other mappers.

When using other mappers (@Mapper.uses) you might also want to use (@Mapper.injectionStrategy) and use constructor injection. Since mappers are stateless by design, you could write some reflective code yourself to construct a mapper with all its dependent uses mappers.