Consider defining a bean of type ''FooMapper" in your configuration

1,027 views
Skip to first unread message

Olufemi Oyenusi

unread,
Sep 16, 2021, 12:25:56 PM9/16/21
to mapstruct-users
Hello, I'm trying to get Mapstruct working with gradle. The implementations generate and work great when I run the service from the boot dashboard in eclipse, but they don't generate when run with gradlew bootrun, and the bean can't be found. Here is the error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field fooMapper in ServiceImpl required a bean of type 'FooMapper' that could not be found.

The injection point has the following annotations:
        - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'FooMapper' in your configuration.


and here is my build.gradle file

plugins {
    id "org.springframework.boot"
    id "groovy"
    id "com.diffplug.eclipse.apt" version "3.31.0" 
}

configurations {
  // configuration to enable running bootRun locally
  // with embedded h2 database
  runlocal
}

ext {
    mapstructVersion = "1.5.0.Beta1"
}

dependencies {
  implementation "org.mapstruct:mapstruct:${mapstructVersion}"
  annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
  testImplementation "org.testng:testng:6.10", "org.easytesting:fest-assert:1.4"
  implementation project(":cpms-common")
  implementation "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
  implementation "org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion"
  implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
  implementation "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
  implementation "org.springframework.boot:spring-boot-starter-validation:$springBootVersion"
  implementation "org.codehaus.gpars:gpars:1.2.1"

  developmentOnly "org.springframework.boot:spring-boot-devtools:$springBootVersion"
  
  runlocal project(":test-db")
  
  testImplementation project(":test-db")
}

sourceSets.main.groovy.srcDirs += ["build/generated/sources"]

bootRun {
  classpath = sourceSets.main.runtimeClasspath + configurations.runlocal
}

tasks.withType(JavaCompile) {
    options.compilerArgs = [
        "-Amapstruct.suppressGeneratorTimestamp=true",
        "-Amapstruct.defaultComponentModel=spring",
        "-Amapstruct.verbose=true"
    ]
}

is it because my code is written in groovy? But then why would it work with the boot dashboard in eclipse? Any help would be really appreciated!

Olufemi Oyenusi

unread,
Sep 16, 2021, 12:33:57 PM9/16/21
to mapstruct-users
I also want to clarify that I am in fact using  @Mapper(componentModel = "spring"), that hasn't fixed the issue
Reply all
Reply to author
Forward
0 new messages