【发布时间】:2021-04-16 16:47:24
【问题描述】:
我将 java spring boot 代码转换为 kotlin,现在我在 map struct 接口和 bean config 类中有错误
这是我的 Mapper 界面
@Component
@Mapper
interface PersonMapper {
fun toPerson(personDTO: PersonDTO?): Person?
fun toPersonDTO(person: Person?): PersonDTO?
fun toPersons(personDTOS: List<PersonDTO?>?): List<Person?>?
fun toPersonDTOs(personList: List<Person?>?): List<PersonDTO?>?
companion object {
@JvmStatic
val INSTANCE: PersonMapper = Mappers.getMapper(PersonMapper::class.java)
}
}
还有我的 Bean 配置
@Configuration
class BeanConfig {
@Bean
@Primary
fun personMapper(): PersonMapper {
return PersonMapper.INSTANCE
}
}
还有我的错误
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personController' defined in file [D:\Zaban\Server\target\classes\ir\ktcoders\zaban\person\PersonController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personService' defined in file [D:\Zaban\Server\target\classes\ir\ktcoders\zaban\person\PersonService.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personMapper' defined in class path resource [ir/ktcoders/zaban/config/BeanConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [ir.ktcoders.zaban.person.PersonMapper]: Factory method 'personMapper' threw exception; nested exception is java.lang.ExceptionInInitializerError
【问题讨论】:
标签: spring-boot kotlin dependency-injection mapstruct