닉추
1k
2022-06-18 14:15:15
3
111

스프링 부트 서비스단에서 bean(mapper) 못 찾는 이유


Description:

Field bookMapper in kwang.ho.service.book.BookServiceImpl required a bean of type 'kwang.ho.mapper.book.BookMapper' that could not be found.

Action:

Consider defining a bean of type 'kwang.ho.mapper.book.BookMapper' in your configuration.

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
위와 같은 오류로 bean을 못 찾는다고 하는데 원인이 뭘까요


1.  BookServiceImpl.java

package kwang.ho.service.book;

@Service
public class BookServiceImpl implements BookService {

@Autowired
private BookMapper bookMapper;

@Override
public List<BookDto> selectBookListWithPaging(PagingVO pagingVO) throws Exception {
return bookMapper.selectBookListWithPaging(pagingVO);
}

}

2. BookService.interface

package kwang.ho.service.book;


public interface BookService {

List<BookDto> selectBookListWithPaging(PagingVO pagingVO) throws Exception;

}

3. BookMapper.interface

package kwang.ho.mapper.book;

public interface BookMapper{

List<BookDto> selectBookListWithPaging(PagingVO pagingVO) throws Exception;
}

4. BookController.java

package kwang.ho.controller.book;

@Controller
@RequiredArgsConstructor
public class BookController {

private final BookService bookService;

@RequestMapping("/bookList.do")
public String selectBookListWithPaging(PagingVO pagingVO, Model model
, @RequestParam(value="nowPage", required=false)String nowPage
, @RequestParam(value="cntPerPage", required=false)String cntPerPage, BookDto bookDto) throws Exception {

model.addAttribute("list", bookService.selectBookListWithPaging(pagingVO));

return "/bookList";
}
}

5. bookMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kwang.ho.mapper.book.BookMapper">

<!-- 도서게시판 목록 조회 -->
<select id="selectBookListWithPaging" parameterType="kwang.ho.dto.board.PagingVO" resultType="kwang.ho.dto.book.BookDto">
<![CDATA[
        select * from board;
]]>
</select>
</mapper>

6. HoApplication(실행파일)

package kwang.ho;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HoApplication {

public static void main(String[] args) {
SpringApplication.run(HoApplication.class, args);
}
}




0
  • 답변 3

  • 닉추
    1k
    2022-06-18 14:24:36

    springbootApplication에 @MapperScan(basePackages = "kwang.ho.mapper")

    넣어주니 되네요..


  • 트리아스
    104
    2022-06-18 14:53:41

    BookMapper 인터페이스 위에 @Mapper 어노테이션이 없어서 그런 것 같네요.

  • 닉추
    1k
    2022-06-21 20:44:07

    감사합니다 트리아스님!

  • 로그인을 하시면 답변을 등록할 수 있습니다.