Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-20664

camel-mapstruct - MapStruct mappers not found in Spring Boot

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Information Provided
    • 4.0.0
    • 4.4.0
    • camel-mapstruct
    • None
    • $ java -version
      openjdk version "17.0.7" 2023-04-18
      OpenJDK Runtime Environment Temurin-17.0.7+7 (build 17.0.7+7)
      OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)

    • Unknown

    Description

      The `DefaultMapStructFinder` is unable to locate the `Mapper` classes when running in Spring Boot. Seems to throw an exception calling `PluginHelper.getPackageScanClassResolver(ecc).findByFilter(f -> f.getName().endsWith("Mapper"), names);` inside the `doInit()` method.

      You can work around this by creating your own `MapStructFinder`, extending `DefaultMapStructFinder`, overriding the `doInit()` function, and calling `discoverMappings(...)` with each of your `Mapper` classes. That way it doesn't try to scan the classpath to find the `Mapper` classes automatically. I've attached a working example to illustrate.

      *Note: It has no issue locating them when running `mvn spring-boot:run`. Only when running from the packaged uber jar with `java -jar ...`.

      Attachments

        1. camel-mapstruct-demo.zip
          23 kB
          Josh Reagan

        Activity

          People

            Unassigned Unassigned
            jreagan Josh Reagan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: