SpringBoot-異常問題總結

一:建立的SpringBoot項目以後測試訪問接口報錯:spring

  Whitelabel Error Page

    This application has no explicit mapping for /error, so you are seeing this as a fallback.springboot

    Thu Feb 28 23:18:21 CST 2019
    There was an unexpected error (type=Not Found, status=404).
    No message available
   問題說明:
    出現這個異常說明了跳轉頁面的url無對應的值.
   緣由:

    緣由1:
      Application啓動類的位置不對.要將Application(啓動類)類放在最外側,即包含全部子包,spring-boot會自動加載啓動類所在包下及其子包下的全部組件.mvc

    緣由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.suffixapp

    緣由3:
      控制器的URL路徑書寫問題
      @RequestMapping(「xxxxxxxxxxxxxx」)
      實際訪問的路徑與」xxx」不符合.spring-boot

    個人緣由:
      註解問題:由於個人代碼以下 使用了@Controller和@RequestMapping兩個註解,返回一個字符串並無對應的解析器,因此就會包錯
      解決方案:
        將這兩個註解換掉使用    @RestController  或者在 @RequestMapping("/hello") 這裏加上@ResponseBody示意不用去找頁面
        @Controller
        public class HelloController {
        @RequestMapping("/hello")
          public String hello(){
            return "hello SpringBoot!!";
          }
        }

二:
相關文章
相關標籤/搜索