springboot 시작 으로 dao 층 인 터 페 이 스 를 스 캔 하지 못 하 는 솔 루 션
2810 단어 springboot스캐닝dao 층인터페이스
해결 하 다.
검사 원인 은 시작 클래스 의 MapperScan(")의 값 이 클래스 이름 에 적 혀 있 는 것 으로 밝 혀 졌 습 니 다.클래스 가 있 는 패키지 이름 오류 로 바 뀌 면 복 구 됩 니 다.
springboot 에서 dao 층 과 controller 를 검색 할 수 없습니다.
힌트
A component required a bean of type'com.imooc 2.product.category.dao.ProductCategory Dao'that could not be found 즉,dao 층 을 찾 을 수 없습니다.
해결:@MapperScan 주석 또는@MapperScans 주석 사용
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@SpringBootApplication
@MapperScan("com.imooc2.product.**.dao")
public class ProductApplication {//extends SpringBootServletInitializer
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);
}
}
2.문제:제시 controller 와 services 층 을 찾 을 수 없습니다
1.시작 클래스 는 디 렉 터 리 아래 에 놓 습 니 다.그림 과 같이 제 contrller 와 service 는 각각 com.imooc 2.produt 의 produt 폴 더 와 category 폴 더 에 있 기 때문에 시작 클래스 는 루트 디 렉 터 리 com.imooc 2.produt 에 놓 아야 합 니 다.
원인:sprigboot 는 루트 디 렉 터 리 아래 의 모든 가방 을 자동 으로 검색 합 니 다.
2.캐 시 또는 프로젝트 시작 클래스 가 controller 층 과 service 층 을 식별 하지 못 하거나 시작 클래스 를 루트 디 렉 터 리 에 내 려 놓 지 않 으 려 면 기본 스 캔 을 하고 싶 지 않 을 수도 있 습 니 다.springboot 2.0.5.RELEASE 로 업데이트 할 수 있 습 니 다.사용자 정의 스 캔 패키지 설명 을 사용 하 십시오.
@ComponentScan(basePackages = {“com.imooc2.product.product”, “com.imooc2.product.category”})
혹은
@SpringBootApplication(scanBasePackages = {“com.imooc2.product.product”, “com.imooc2.product.category”})
둘 중 하 나 를 선택 하면 그림 과 같다.
@SpringBootApplication(scanBasePackages = {"com.imooc2.product","com.imooc2.product.**.dao"})//
@ComponentScan(basePackages = {"com.imooc2.product.product", "com.imooc2.product.category"})//
@MapperScan("com.imooc2.product.**.dao")
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);
}
}
메모:잘못된 주 해 를 사용 하지 마 십시오.이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin Springboot -- 파트 14 사용 사례 REST로 전환하여 POST로 JSON으로 전환前回 前回 前回 記事 の は は で で で で で で を 使っ 使っ 使っ て て て て て リクエスト を を 受け取り 、 reqeustbody で 、 その リクエスト の ボディ ボディ を を 受け取り 、 関数 内部 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.