[英]No qualifying bean with MapStruct
使用 MapStruct、Lombok 和 Spring 时,在 Tomcat 9 中部署应用程序时出现以下错误:
没有可用的“somepackage.ControllerBusinessMapper”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选
这是我的 pom.xml:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>[1.18.12,)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>1.3.1.Final</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.1.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
这是映射器:
@Mapper(componentModel = "spring")
public interface ControllerBusinessMapper {
//Some methods
}
在注入的类中:
@Autowired
private ControllerBusinessMapper businessMapper;
我的 spring 配置类在包层次结构的根中设置包扫描。 并且映射器的实现也是在 target/generated-sources 下生成的:
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2020-08-23T03:56:23+0200",
comments = "version: 1.3.1.Final, compiler: javac, environment: Java 11.0.7 (Oracle Corporation)"
)
@Component
public class ControllerBusinessMapperImpl implements ControllerBusinessMapper {
//Some methods
}
我遇到的错误表明 Spring 无法找到实现类,我错过了什么? 我尝试将生成的源文件夹添加到构建路径并将其包含在包扫描中,但它没有用。
为了使用 MapStruct,需要在 Eclipse 中进行其他配置:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.