故事背景

之前尝试过用 INSTANCE 方式来使用 MapStruct,但作为 Spring 玩家,还是习惯于使用 Bean 的方式来注入,于是乎发现注入失败!!!

报错信息

Consider defining a bean of type in your configuration.

解决方案

  • 其实还是 Maven 里 Lombok 和 MapStruct 兼容性问题引起的,如下附上正确配置方案
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.18.RELEASE</version><relativePath/></parent><groupId>com.weink</groupId><artifactId>weink-server</artifactId><version>0.0.1-SNAPSHOT</version><name>weink-server</name><description>weink-server</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><optional>true</optional></dependency><dependency><groupId>org.mapstruct</groupId><artifactId>mapstruct</artifactId><version>1.4.1.Final</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><annotationProcessorPaths><path><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version></path><path><groupId>org.mapstruct</groupId><artifactId>mapstruct-processor</artifactId><version>1.4.1.Final</version></path></annotationProcessorPaths></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>
package com.luxsun.weink.convert;import com.luxsun.weink.domain.dto.organ.OrganDTO;
import com.luxsun.weink.domain.po.organ.OrganPO;
import com.luxsun.weink.domain.vo.organ.OrganVO;
import org.mapstruct.Mapper;/*** @author Lux Sun* @date 2022/7/18*/
@Mapper(componentModel = "spring")
public interface OrganMapper {OrganPO organDtoToPo(OrganDTO organDto);OrganDTO organVoToDto(OrganVO OrganVo);
}
/*** @author Lux Sun* @date 2022/7/8*/
@Slf4j
@RestController
@RequestMapping("/organ")
public class OrganController {@Resourceprivate OrganService organService;@Resourceprivate OrganMapper organMapper;/*** 新增机构* @param organVo*/@PostMappingpublic ResultVO<Object> insertOrgan(@RequestBody OrganVO organVo) {OrganDTO organDto = organMapper.organVoToDto(organVo);organService.insertOrgan(organDto);return ResultVoUtil.buildSuccess();}
}

MapStruct - Consider defining a bean of type in your configuration.相关推荐

  1. Spring Boot:Consider defining a bean of type ‘*.*.*‘ in your configuration解决方案

    Spring Boot:Consider defining a bean of type '*.*.*' in your configuration解决方案 参考文章: (1)Spring Boot: ...

  2. Maven多模块开发Action:Consider defining a bean of type '*.*.*' in your configuration解决

    最近在使用maven构建多模块进行Springboot和mybatits开发时,总遇到一些稀奇古怪的错误,在模块引用的时候,使用改对象并不报错,但是在启动项目时遇到类找打不到的错误,后来找到了解决方法 ...

  3. Spring Boot引用jar包报错:Consider defining a bean of type '***' in your configuration

    错误信息: Spring boot Consider defining a bean of type '***SpringDataUserDetailsService' ...... Action: ...

  4. springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.

    一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description:Field userEntityMapper in com.xxx.x ...

  5. Consider defining a bean of type ‘java.lang.String‘ in your configuration

    Consider defining a bean of type 'java.lang.String' in your configuration 总结了网上的几种解决方案: 1.多余的@autowi ...

  6. Consider defining a bean of type ‘com.xg.stupro.service.StudentService‘ in your configuration.

    1.运行sprring boot项目时,出现这个错误:Consider defining a bean of type 'com.xg.stupro.service.StudentService' i ...

  7. springboot 启动项目报Consider defining a bean of type 'com.mooc.house.biz.service.XXX' in your config

    报错: Error starting ApplicationContext. To display the auto-configuration report re-run your applicat ...

  8. Consider defining a bean of type ‘cn.itcast.feign.clients.UserClient‘ in your configuration.解决方案

    Consider defining a bean of type 'cn.itcast.feign.clients.UserClient' in your configuration.解决方案 Fei ...

  9. 关于spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决方案

    搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...

最新文章

  1. 《科学》杂志做了一个清单,告诉你今年 10 个最重要的科技突破
  2. 运维基础(3)备份篇
  3. 【Python】Python的类和对象(长文系列第⑤篇)
  4. 中运量71路线路图_双语导乘对标“航空式服务”,71路中运量车队服务进博会出“新招”...
  5. 连接池,数据库连接池
  6. JavaFX 2.0 Hello World
  7. Python 实现微信小程序的用户登录
  8. LNMP-Linux下Nginx+MySQL+PHP+phpMyAdmin+eAcelerator一键安装包
  9. 解决PHP导出大量数据时设置超链接的问题 --mxp
  10. python入门经典 财务-财务方面的学生如何学习python?
  11. ROS - 科大讯飞语音包使用
  12. 基于大数据平台的城市规划设计
  13. 联通loid认证_光纤LOID 认证 需要填写的用户名是什么?有人说不需要填写密码。为什么我每次认证都是超时?...
  14. 【高等数学】方差的集合意义
  15. bzoj 5394: [Ynoi2016]炸脖龙 扩展欧拉定理+树状数组
  16. 拔丝芋头的Java学习日记--Day3
  17. 好用的图形工具yEd Graph Editor
  18. Java指导书练习题——抽象类
  19. cad显示有点暗_CAD参照的图框颜色太暗怎么办?CAD调整参照图纸明暗的方法
  20. css自适应图片样式,css怎么让图片自适应?css图片自适应大小的方法介绍

热门文章

  1. MST1662,摩托车大功率闪光器
  2. 3d全景效果图和普通图片的区别,北京同创蓝天提供哪些服务?
  3. [LiteratureReview]ORB-SLAM2: an Open-Source SLAM System for Monocular, Stereo and RGB-D Cameras
  4. 全球最火的程序员学习路线!没有之一!3天就在Github收获了接近1w点赞
  5. Zemax操作11--光纤耦合输出光束整形设计(圆光斑)
  6. java酒店的点评功能实现,基于JAVA的酒店管理系统
  7. 美术线上教育哪家好?美术集网校了解一下
  8. Python爬取搜狐车型数据
  9. 港口AI叉车自动化辅助驾驶系统
  10. Thinkphp开发App网络授权验证系统源码