前幾天自己沒事,搭建了一個框架,出現了這個錯誤在網上查了半天招錯誤,但是還是一直沒有找到解決問題的辦法,最後還是解決了,
@Slf4j
@SpringBootApplication
@ComponentScan(basePackages = {"com.baoboyun.generator.mapper"})
//@MapperScan(basePackages = {"com.baoboyun.generator.mapper"})
@EnableSwagger2
public class GApplication {
public static void main(String[] args) {
log.info("----------------項目啓動開始-----------------------");
SpringApplication.run(GApplication.class,args);
log.info("----------------項目啓動成功-----------------------");
}
}
@ComponentScan(basePackages = {“com.baoboyun.generator.mapper”}) 如果我用這個註解就會出現以下情況:
最後我把註解換成了如下圖:
@Slf4j
@SpringBootApplication
//@ComponentScan(basePackages = {"com.baoboyun.generator.mapper"})
@MapperScan(basePackages = {"com.baoboyun.generator.mapper"})
@EnableSwagger2
public class GApplication {
public static void main(String[] args) {
log.info("----------------項目啓動開始-----------------------");
SpringApplication.run(GApplication.class,args);
log.info("----------------項目啓動成功-----------------------");
}
}
這樣就不會寶上面那個錯誤,@SpringBootApplication 裏面包含@ComponentScan,所以是兩個起衝突了,
換成了@ComponentScan 指定掃描的包就可以了,
查看兩個關係的可以跳轉到下面的鏈接上:
https://www.cnblogs.com/oskyhg/p/6683629.html
除了上面我遇到的錯誤,也有可能是下面的幾個錯誤:
出現這個異常說明了跳轉頁面的url無對應的值.
原因1:
Application啓動類的位置不對.要將Application類放在最外側,即包含所有子包
原因:spring-boot會自動加載啓動類所在包下及其子包下的所有組件.
原因2:
在springboot的配置文件:application.yml或application.properties中關於視圖解析器的配置問題:
當pom文件下的spring-boot-starter-paren版本高時使用:
spring.mvc.view.prefix/spring.mvc.view.suffix
當pom文件下的spring-boot-starter-paren版本低時使用:
spring.view.prefix/spring.view.suffix
原因3:
控制器的URL路徑書寫問題
@RequestMapping(“xxxxxxxxxxxxxx”)
實際訪問的路徑與”xxx”不符合.