[英]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. PostMapper
的interface
没有任何实现它的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.