简体   繁体   English

考虑在配置问题中定义类型的 bean

[英]Consider defining a bean of type in your configuration issue

I'm trying to access @Mapper annotated interface in my @Service class我正在尝试访问我的@Service class 中的@Mapper注释接口

here is my Service class这是我的服务 class

@Service
public class PostServiceImpl implements PostService {

    private PostRepository postRepository;
    private PostMapper postMapper;

    public PostServiceImpl(PostRepository postRepository, PostMapper postMapper) {

        this.postRepository = postRepository;
        this.postMapper = postMapper;
    }

    @Override
    public PostDto createPost(PostDto postDto) {

        Post npo = postMapper.getPost(postDto);
        postRepository.save(npo);
        PostDto retrunStatus = postMapper.getPostDto(npo);

        return retrunStatus;

    }

    @Override
    public List<PostDto> getAllPosts() {
        // TODO Auto-generated method stub
        return null;
    }

}

and here is my Mapper class这是我的映射器 class

@Mapper( imports = {Instant.class, DateTimeFormatter.class})
@Configuration
public interface PostMapper {
    
    Post getPost(PostDto postDto);
    
    PostDto getPostDto(Post post);

}

but am getting below error, while starting spring boot application但是在启动 spring 启动应用程序时出现以下错误

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in com.rest.api.service.impl.PostServiceImpl required a bean of type 'com.rest.api.mapper.PostMapper' that could not be found.


Action:

Consider defining a bean of type 'com.rest.api.mapper.PostMapper' in your configuration.

It was running fine when I was not using mapper but using manually mapping PostDto to Post当我不使用映射器但使用手动将PostDto to Post时,它运行良好

Can anyone suggest what am doing wrong here?谁能建议这里做错了什么?

PostMapper 's interface doesn't have any bean in which implements it. PostMapperinterface没有任何实现它的bean For example:例如:

@Component
public class PostMapperImpl implements PostMapper{
  // override the PostMapper methods
}

BTW, the error that Spring throws tell you that.顺便说一句,Spring 抛出的错误告诉你。

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

相关问题 考虑在你的配置中定义一个类型为 * 的 bean - Consider defining a bean of type * in your configuration 考虑在配置中定义“包”类型的bean - Consider defining a bean of type 'package' in your configuration 考虑在你的配置中定义一个 'form' 类型的 bean - Consider defining a bean of type 'form' in your configuration 考虑在您的配置中定义一个类型的 bean - Consider defining a bean of type in your configuration 例外:考虑在你的配置中定义一个类型的 bean - Exception: Consider defining a bean of type in your configuration 考虑在您的配置中定义类型为“UserConverter”的 bean - Consider defining a bean of type 'UserConverter' in your configuration 考虑在你的配置中定义一个 '...' 类型的 bean - Consider defining a bean of type '...' in your configuration Redis问题考虑在您的配置中定义类型为“ org.springframework.data.redis.core.HashOperations”的bean - Redis Issue Consider defining a bean of type 'org.springframework.data.redis.core.HashOperations' in your configuration 考虑在配置中定义类型为&#39;javax.persistence.EntityManagerFactory&#39;的bean - Consider defining a bean of type 'javax.persistence.EntityManagerFactory' in your configuration 考虑在您的配置中定义类型为“org.hibernate.SessionFactory”的 bean - Consider defining a bean of type 'org.hibernate.SessionFactory' in your configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM