I have the following parts in my gradle file:
apply plugin: 'kotlin-kapt'
...
compile("org.mapstruct:mapstruct:1.3.0.Final")
kapt("org.mapstruct:mapstruct-processor:1.3.0.Final")
And am also using JUnit 5.
My mapper looks like:
@Mapper(componentModel = "spring")
interface ModelMapper {
fun convertToDto(forms: Model): DTO
@InheritInverseConfiguration
fun convertToModel(dto: DTO): Model
}
And I'm trying to autowire it similar to such:
@Service
@Transactional
class MyService @Autowired constructor(
private val repository: MyRepository,
private val mapper: ModelMapper
) {
...
}
But when I try to run a test/do a build, I get an error:
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '....ModelMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Does anyone know why Spring Boot isn't working with this kind of setup?
Try passing Spring's annotation processor to kapt in build.gradle
:
kapt("org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}")
or try keeping javac annotation processors:
kapt {
keepJavacAnnotationProcessors = true
}
this helped me, add this in your build.gradle.kts:
implementation("org.mapstruct:mapstruct")
kapt("org.mapstruct:mapstruct-processor")
compileOnly(group = "org.springframework.boot", name = "spring-boot-configuration-processor")
kapt(group = "org.springframework.boot", name = "spring-boot-configuration-processor")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With