简体   繁体   English

考虑在您的配置中定义一个类型为“Mapper”的 bean [Spring-Boot]

[英]Consider defining a bean of type 'Mapper' in your configuration [Spring-Boot]

mapstruct doesn't work on my Spring Boot project. mapstruct 不适用于我的 Spring 引导项目。

I added dependencies, path, Mapper annotations (componentModel="spring") in the mapper interface and still get the same error我在mapper接口中添加了依赖、路径、Mapper注解(componentModel="spring"),仍然报同样的错误

https://i.stack.imgur.com/CHTPo.png https://i.stack.imgur.com/CHTPo.png

https://i.stack.imgur.com/nvxo4.png https://i.stack.imgur.com/nvxo4.png

CategoryMapper is a Entity? CategoryMapper 是实体吗? if it is kindly add this @NoArgsConstructor becoause its looking for empty constructor如果它是请添加这个 @NoArgsConstructor 因为它正在寻找空构造函数

@NoArgsConstructor
public class CategoryMapper {

    
}

if you dont have lombok just add this如果你没有龙目岛只需添加这个

//empty constructor
public CategoryMapper() {

}

If this class is Repository make sure to hava @Mapper如果这个 class 是 Repository 确保有 @Mapper

@Mapper
public class CategoryMapper {

    
}

Dont forget also do add this to SpringApplication runner class. This class is generated when you first created the project file不要忘记将它添加到 SpringApplication runner class。这个 class 是在您第一次创建项目文件时生成的

@Bean
    public ModelMapper modelMapper() {
        return new ModelMapper();
    }

//For repsitory dont forget this.
//This will be added upper of the class in springapplication class runner

@MappedTypes({YourEntity.class})
@MapperScan("package patch to you repository")


This is the interface Code @SpicySandwich这是接口代码@SpicySandwich

`@Mapper(componentModel = "spring") public interface SubredditMapper { `@Mapper(componentModel = "spring") 公共接口 SubredditMapper {

@Mapping(target = "numberOfPosts", expression = "java(mapPosts(subreddit.getPosts()))")
SubredditDto mapSubredditToDto(Subreddit subreddit);

default Integer mapPosts(List<Post> numberOfPosts) {
    return numberOfPosts.size();
}

@InheritInverseConfiguration
@Mapping(target = "posts", ignore = true)
Subreddit mapDtoToSubreddit(SubredditDto subredditDto);

}` }`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 考虑在您的配置中定义一个类型为“package”的 bean [Spring-Boot] - Consider defining a bean of type 'package' in your configuration [Spring-Boot] 考虑在您的配置中定义一个“服务”类型的 bean [Spring boot] - Consider defining a bean of type 'service' in your configuration [Spring boot] 使用 Spring JpaRepository 时,请考虑在 spring 引导中的配置中定义一个类型的 bean - Consider defining a bean of type in your configuration in spring boot when using Spring JpaRepository Spring Boot:考虑在配置中定义一个名为“ entityManagerFactory”的bean - Spring Boot: Consider defining a bean named 'entityManagerFactory' in your configuration 考虑在您的配置-Spring 启动中定义一个名为“entityManagerFactory”的 bean - Consider defining a bean named 'entityManagerFactory' in your configuration-Spring boot Java Spring 引导:考虑在配置中定义一个名为“entityManagerFactory”的bean - Java Spring Boot: Consider defining a bean named 'entityManagerFactory' in your configuration Spring 引导 - 将存储库注入 Controller 抛出考虑在配置中定义类型为“Type”的 bean - Spring Boot - Injecting Repository into Controller throws Consider defining a bean of type 'Type' in your configuration Spring 引导/MVC:考虑在配置中定义类型为“pack.website.repositories.CustomerRepository”的 bean - Spring Boot/MVC: Consider defining a bean of type 'pack.website.repositories.CustomerRepository' in your configuration 春季启动:考虑在配置中定义类型为“ com.repository.services.interfacename”的bean - Spring boot: Consider defining a bean of type 'com.repository.services.interfacename' in your configuration 考虑在你的配置中定义一个类型为 * 的 bean - Consider defining a bean of type * in your configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM