在使用mapstruct、lombock和spring时,在tomcat 9中部署应用程序时出现以下错误:
没有“somepackage.controllerbusinessmapper”类型的合格bean可用:至少需要1个符合autowire候选条件的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>
这是Map器:
@Mapper(componentModel = "spring")
public interface ControllerBusinessMapper {
//Some methods
}
在课堂上,它被注入了:
@Autowired
private ControllerBusinessMapper businessMapper;
我的spring配置类在包层次结构的根目录中设置包扫描。Map器的实现也在目标/生成源下生成:
@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无法找到实现类,我遗漏了什么?我试图将生成的sources文件夹添加到构建路径,并将其包含在包扫描中,但没有成功。
1条答案
按热度按时间cwdobuhd1#
为了使用mapstruct,需要在eclipse中进行其他配置:
安装m2e apt插件
在每个maven模块中,转到maven>annotation processing
选中“启用项目特定设置”
选择自动配置jdt apt模式