Implementations do not get generated

4,494 views
Skip to first unread message

Jędrzej Nowacki

unread,
Nov 15, 2016, 10:37:55 AM11/15/16
to mapstruct-users
Hi!
I'm sorry if this question is somehow trivial or I make some obvious error, I am quite beginner developer.

I tried to use mapstruct, but did not manage to do so with my spring project in Eclipse, i got message the implementation of interface was not found. So i figured there may be multiple errors, like something related to IDE, DI etc. So i set up a simple project based on example on your site and ran in with Maven directly from CL. I'm an expert in Maven, I just ran it like "mvn test" to see how that work. It failed my simple test. Should I ran maven with some arguments? Or is there something wrong in my project? Can you guys take a look? I have some personal project with a lot of entities and it would make my life so much easier.

If there is something fundamentally wrong with the way i run maven or something let me know, I will just get some book on it or something. I just learn java web development and usually used build tools provided by IDE, they used to do the job with little configuration effort.

Here is my project, as I said it is copied from example:

Thanks for your time!

Jędrzej Nowacki

unread,
Nov 15, 2016, 10:40:00 AM11/15/16
to mapstruct-users
Of course i meant that I'm not an expert in Maven :)

Filip Hrisafov

unread,
Nov 15, 2016, 2:39:22 PM11/15/16
to mapstruct-users
Hey,

What kind of error are you getting?

I had a quick look at your repo and your Car and CarDto are missing default constructors. For now MapStruct uses only the default constructor for creating objects. You should be getting some compile error like "constructor CarDto in class example.main.CarDto cannot be applied to given types;"

Cheers,
Filip

Filip Hrisafov

unread,
Nov 15, 2016, 2:42:45 PM11/15/16
to mapstruct-users
I forgot to add the link for the open issue about the new feature #73 (Make use of constructor arguments when instantiating mapping targets)

Jędrzej Nowacki

unread,
Nov 16, 2016, 4:38:38 AM11/16/16
to mapstruct-users
I checked and it does not work with default constructors either. I get this error as a root cause:

Caused by: java.lang.ClassNotFoundException: Cannot find implementation for example.main.CarMapper
 at org
.mapstruct.factory.Mappers.getMapper(Mappers.java:93)
 at org
.mapstruct.factory.Mappers.getMapper(Mappers.java:76)
 
... 31 more

It seems like interface is not processed and implementations are not generated. Should i do something special with Maven for it to kick in? Or should config in pom.xml be enough?

Filip Hrisafov

unread,
Nov 17, 2016, 1:11:51 PM11/17/16
to mapstruct-users
Does mvn clean install work with the default constructor?

I tried your project with the default constructor and it was working. However, for some reason the generated Mapper (CarMapperImpl) was located in target/classes. Can you push all your changes to your repo and I can have a look at it.

Cheers,
Filip

Jędrzej Nowacki

unread,
Nov 24, 2016, 8:31:26 AM11/24/16
to mapstruct-users
I finally got time to look at that. Indeed, default constructors were the answer, one stupid error i made was not using "clean" when building project, as I said I am quite beginner. Thanks for your assistance!
Reply all
Reply to author
Forward
0 new messages