-
I used mapstruct years ago and am picking it up for this existing project I joined. I am trying something pretty basic and defined the following mappers:
and another going the opposite direction:
where my config class looks as follows:
I started out with trying to inject the ConversionService into a bean but was getting a spring error that I had 2 conversion beans in my path: mvcConversionService and defaultConversionService.
always results in this exception:
Do I need to define some Configuration class? It must be something simple I am missing. |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 3 replies
-
@Chessray is this something that you might be able to help with? |
Beta Was this translation helpful? Give feedback.
-
Could you tell us a bit more about the project setup? A standard Spring Boot project typically picks this up out of the box. @basven Just to clarify: From Spring's point of view, everything is registered as a Bean, but depending on your setup you might need to add the converters to the conversion service separately. See the tests for examples of that. |
Beta Was this translation helpful? Give feedback.
-
This project uses spring boot 2.7.6 but I noticed it also pulled in a
dependency on spring cloud. I don't think it needs that so i will see what
happens when I remove that. I will also look at those tests you
mentioned, I missed that.
…On Sat, Jul 29, 2023, 10:31 Raimund Klein ***@***.***> wrote:
Could you tell us a bit more about the project setup? A standard Spring
Boot project typically picks this up out of the box. @basven
<https://github.com/basven> Just to clarify: From Spring's point of view,
everything is registered as a Bean, but depending on your setup you might
need to add the converters to the conversion service separately. See the
tests for examples
<https://github.com/mapstruct/mapstruct-spring-extensions/blob/main/examples/noconfig/src/test/java/org/mapstruct/extensions/spring/example/ConversionServiceAdapterIntegrationTest.java>
of that.
—
Reply to this email directly, view it on GitHub
<#3336 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAROFYMK6R6NCSEQ2QJLC6DXSU3EJANCNFSM6AAAAAA2O5EFQM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Most Spring Boot projects will configure automatically. But AFAIR this requires the web module. If your project doesn't use that, I recommend looking at this example. |
Beta Was this translation helpful? Give feedback.
-
Pretty sure we have the web starter dependency
…On Sat, Jul 29, 2023, 13:53 Raimund Klein ***@***.***> wrote:
Most Spring Boot projects will configure automatically. But AFAIR this
requires the web module. If your project doesn't use that, I recommend
looking at this
<https://github.com/mapstruct/mapstruct-spring-extensions/blob/main/examples/simple-springboot/src/main/java/org/mapstruct/extensions/spring/example/boot/config/ConverterConfig.java>
example.
—
Reply to this email directly, view it on GitHub
<#3336 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAROFYKCYYXWMRM2WXRJXP3XSVS3JANCNFSM6AAAAAA2O5EFQM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thanks @Chessray for looking into this. @basven if it doesn't work like @Chessray explained then please provide us a minimal reproducible example that we can try out. |
Beta Was this translation helpful? Give feedback.
-
One more thing that strikes me as very unusual is that you mentioned having two |
Beta Was this translation helpful? Give feedback.
-
This worked for me. Defined a bean in my main app like this:
Inject and test it:
Of course the registration might become a nightmare when there are a lot of converters. |
Beta Was this translation helpful? Give feedback.
-
The better solution is the one @Chessray suggested later, which is this one |
Beta Was this translation helpful? Give feedback.
Most Spring Boot projects will configure automatically. But AFAIR this requires the web module. If your project doesn't use that, I recommend looking at this example.