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

mapstruct doesn't work on my Spring Boot project.

I added dependencies, path, Mapper annotations (componentModel="spring") in the mapper interface and still get the same error

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

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



Solution 1:[1]

CategoryMapper is a Entity? if it is kindly add this @NoArgsConstructor becoause its looking for empty constructor

@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

@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

@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")


Solution 2:[2]

This is the interface Code @SpicySandwich

`@Mapper(componentModel = "spring") public interface 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);

}`

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Artizoz Frank