当前位置: 首页 > 知识库问答 >
问题:

如何解决Spring中注入bean Mapstruct的错误

云宏儒
2023-03-14

我正在尝试使用mapstruct注入我的映射器,但Spring无法识别bean。

这是我的制图仪

package com.api.gestioncartera.Services.Mappers;

import org.mapstruct.Mapper;
import org.springframework.stereotype.Component;

import com.api.gestioncartera.Entities.CollectionCompany;
import com.api.gestioncartera.Services.DTO.CollectionCompanyDto;

@Mapper(componentModel = "spring")
public interface CollectionCompanyMapper {
    CollectionCompanyDto collectionCompanyToCollectionCompanyDto(CollectionCompany collectionCompany);
}

我正在尝试注入我的服务

@Service
@Transactional
public class CollectionCompanyServiceImp implements CollectionCompanyService{
    
    @Autowired
    private CollectionCompanyMapper companyMapper;
}

我的毕业生配置

plugins {
    id 'org.springframework.boot' version '2.5.6'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}
...
dependencies {
    ...
    implementation 'org.mapstruct:mapstruct:1.4.2.Final'
 
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'

}
compileJava {
    options.compilerArgs += [
        '-Amapstruct.suppressGeneratorTimestamp=true',
        '-Amapstruct.suppressGeneratorVersionInfoComment=true',
        '-Amapstruct.verbose=true',
        '-Amapstruct.defaultComponentModel=spring'
    ]
}

我还在 IDE 的 IDE 属性中启用注释处理

错误是:

考虑在配置中定义一个类型为“com.api.gestioncartera.Services.Mappers.CollectionCompanyMapper”类型的Bean。

我正在使用Spring Tool Suite 4(Eclipse)Gradle 6.8 SrpingBoot 2.5.6请帮助!!

共有1个答案

敖淮晨
2023-03-14

Eclipse在注释处理方面存在问题。

我用这个插件解决了我的项目中的问题:

https://plugins.gradle.org/plugin/

将此添加到你的gradle插件顶部。

plugins {
  id "eclipse"
  id "com.diffplug.eclipse.apt" version "3.37.1"
}

然后做梯度刷新。

如果仍不工作,请运行

./gradlew eclipse eclipseJdtApt eclipseFactorypath

希望这有帮助!

 类似资料:
  • 我是Spring开机Rest服务的新手。我已经使用maven项目在spring boot中开发了一些rest api。 我已经成功地开发了Get和Post API。我的GET方法在邮递员和移动中工作正常。当我试图从邮递员击中邮政方法,它工作正常,但从移动,它给出403禁止错误。 这是我的配置: 请建议我如何解决错误。

  • tensorflow_安装_测试。派克 以下是输出: 我该如何解决这个问题?

  • 我是Django新手,试图在virtualenv中创建一个Django项目来学习,但在上出现以下错误: 回溯(最后一次调用):文件“manage.py”,第21行,main() 文件“manage.py”,第17行,从命令行执行(sys.argv) 文件 “/home/suraj/Documents/my_projects/django_project/venv/lib/python3.6/sit

  • 我一直试图从AWS S3桶读取一些数据到Databricks。S3桶是开发/团队/用户。我使用的是Scala语句: 我得到以下信息: com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException:用户[user]无权在资源上执行sts: AssumeRole:[资源] 如何解决此错误?我正在运行的数据砖集群有

  • 本文向大家介绍如何解决redisTemplate注入为空问题,包括了如何解决redisTemplate注入为空问题的使用技巧和注意事项,需要的朋友参考一下 springboot2.*集成redis时,redis工具类中的redisTemplate注入后总是为空。 问题代码还原:   1、工具类定义成静态工具类,@Resource注入redisTemplate   2、控制层直接调用工具类的静态方法

  • 本文向大家介绍详解Spring中接口的bean是如何注入的,包括了详解Spring中接口的bean是如何注入的的使用技巧和注意事项,需要的朋友参考一下 Question: 这个问题困扰了我好久,一直疑问这个接口的bean是怎么注入进去的?因为只看到使用@Service注入了实现类serviceImpl,使用时怎么能获取的接口,而且还能调用到实现类的方法,难道这个接口是在什么时候自动注入了进去,且和