首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@Mapper UnsatisfiedDependencyException部署时

@Mapper UnsatisfiedDependencyException部署时
EN

Stack Overflow用户
提问于 2020-10-04 10:22:26
回答 1查看 885关注 0票数 0

我要在服务课上上UnsatisfiedDependecyException @Autowired private ApplicantDetailMapper mapper;。在服务类存储库中,也是自动存储库,并且它们是工作的,因此假设组件扫描工作。

我对这个问题一无所知。

使用spring的Mapper接口

代码语言:javascript
复制
@Mapper(componentModel = "spring")
public interface ApplicantDetailMapper {

 ApplicantEntity dtoToEntity(ApplicantDto source);

}

它是自动服务的服务

代码语言:javascript
复制
@Service
@Transactional
public class ApplicantDetailServiceImpl implements ApplicantDetailService {

@Autowired
private ExampleRepository repo;

@Autowired
private ApplicantDetailMapper mapper;

}

在pom.xml中设置

代码语言:javascript
复制
<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.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
        
    <properties>
      <org.mapstruct.version>1.4.0.Final</org.mapstruct.version>
    </properties>

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
        <version>${org.mapstruct.version}</version>
    </dependency>

异常

代码语言:javascript
复制
Unsatisfied dependency expressed through field 'applicantDetailService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicantDetailServiceImpl': Unsatisfied dependency expressed through field 'mapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.dtos.mappers.ApplicantDetailMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

编辑

面向企业Java开发人员的Eclipse 2020-06

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-04 15:08:09

根据官方文件

如果您正在使用Eclipse,请确保具有当前版本的M2E插件。当导入如上面所示的Maven项目时,它将设置MapStruct注释处理器,以便只要您保存映射器类型,它就可以在IDE中运行。很干净,不是吗?若要再次检查所有操作是否正常,请转到项目的属性,并选择"Java“→”注释处理“→"Factory路径”。应该列出并启用MapStruct处理器JAR。任何通过编译器插件(见下文)配置的处理器选项都应该列在"Java“→”注释处理“下面。如果处理器没有启动,请检查是否启用了通过M2E对注释处理器的配置。要做到这一点,请转到"Preferences“→"Maven”→“注解处理”并选择“自动配置JDT”。或者,在POM文件的属性部分中指定以下内容:jdt_apt.还要确保您的项目使用的是Java1.8或更高版本(项目属性→"Java“→”编译遵从级别“)。它将不适用于旧版本。

因此,正如它所说的,工厂路径应该显示列出并启用的MapStruct Jar。对我来说根本不存在。

设置"Automatically configure JDT APT"导致eclipse显示Maven更新错误。详细情况如下

Utility和DynamicWebModule3.1都不能被选中。

因此,对我来说,在pom.xml properties中添加pom.xml properties解决了这个问题。

资料来源: MapStruct文档

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64193455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档