Spring Boot 错误总结(累计10个常见错误)

1.新建Spring boot,出现src的包上出现错误的叉号:

分析原因: 你要更新一下选择项目-----Maven----Updata project,或者删除jar包—Libraries—Maven Dependencies,然后重新关闭eclipse,重新启动!

2.如果你项目与别人一样,怎么试都不行,还是报错,或者其它问题:

分析原因:记住一句话,小问题重启,大问题重装!

3.启动时出现警告:

分析原因: 项目目录设计错误

                 src
                 |_main
                 |_java
                 |_package name
                 |_xxxController

                 |_Application

                application.Java 文件不能直接放在main/java文件夹下,必须要建一个包把他放进去

4.Web项目无法访问resources/templates/xxx.html文件

分析原因:没有导入相关模板的依赖

5.启动时出现NoSuchBeanDefinitionException: No qualifying bean of type [con: No qualifying bean of type

分析原因:@SpringApplicationConfiguration

6.BasicErrorController提供两种返回错误一种是页面返回、当你是页面请求的时候就会返回页面,另外一种是json请求的时候就会返回json错误:

分析原因:

 @RequestMapping(produces = "text/html")
    public ModelAndView errorHtml(HttpServletRequest request,
            HttpServletResponse response) {
        HttpStatus status = getStatus(request);
        Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(
                request, isIncludeStackTrace(request, MediaType.TEXT_HTML)));
        response.setStatus(status.value());
        ModelAndView modelAndView = resolveErrorView(request, response, status, model);
        return (modelAndView == null ? new ModelAndView("error", model) : modelAndView);
    }
 
    @RequestMapping
    @ResponseBody
    public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
        Map<String, Object> body = getErrorAttributes(request,
                isIncludeStackTrace(request, MediaType.ALL));
        HttpStatus status = getStatus(request);
        return new ResponseEntity<Map<String, Object>>(body, status);
 
          }

7.javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/login] again出现错误:

分析原因:

当没有声明ViewResolver时,spring会注册一个默认的ViewResolver,就是JstlView的实例, 该对象继承自InternalResoureView。
JstlView用来封装JSP或者同一Web应用中的其他资源,它将model对象作为request请求的属性值暴露出来, 并将该请求通过javax.servlet.RequestDispatcher转发到指定的URL.
Spring认为, 这个view的URL是可以用来指定同一web应用中特定资源的,是可以被RequestDispatcher转发的。
也就是说,在页面渲染(render)之前,Spring会试图使用RequestDispatcher来继续转发该请求。

解决:消除缺省转发,修改view和path,让他们不同名。

8.当以.yml结尾的配置出现报错:

分析原因:

             if xxxxxx:

            (空格)xxxxx

9.当出现错误java.net.BindException: Address already in use: bind

解决:打开Windows进程管理器结束javaw.exe,重新运行。并在每次启动程序前,结束之前的运行。

10.当出现错误Spring Boot Error: java.lang.NoSuchMethodError

解决:仔细搜索报错信息中的方法名,查看出错类中是否缺少某方法。笔者此次报错由于org.springframework.core.ResolvableType.forInstance方法找不到所致,又想起 之前在pom.xml中移除了parent依赖,想起是否改文件没有完整下载。查询了官网说明:当移除parent依赖时,需要增加spring-boot-dependencies的依赖。因此pom.xml中在前新增以下依赖。

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>1.3.3.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值