jmnarloch/modelmapper-spring-boot-starter

Configuration issue

Closed this issue · 2 comments

I have an issue where I define multiple mappings by extending PropertyMapConfigurerSupport, and also a configuration by implementing ModelMapperConfigurer. In my configuration I set the matching strategy to STRICT.

The issue I am having is that the configuration is not set before the mappings are.

In ModelMapperFactoryBean.java, in the configure method, the list of configurers is in alphabetical order. If my configuration class starts with a letter before any of my mapping classes, I dont have an issue. But if it is somewhere else in the list, ModelMapper throws an error, which would be avoided if my matching strategy was set to STRICT.

Is there a way I can force the configuration to run before the mappings? Can you update your code to have this happen?

Thanks,
Jason

Hey Jason,

I think that there is no need to make changes in this module at all. What you should be able to do is leverage the Spring's ordering functionality by using @order annotation, you can place that on your bean class declaration or on the @configuration methods. I have prepared a test that illustrates your use case: https://github.com/jmnarloch/modelmapper-spring-boot-starter/blob/master/src/test/java/com/github/jmnarloch/spring/boot/modelmapper/ModelMapperOrdererConfigurerTest.java#L120

Hope that this helps.

Thanks for the quick response. Using the @order annotation solved my issue. Thanks again!