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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot中,可以通过实现CommandLineRunner或ApplicationRunner接口,在应用启动后加载全局变量并进行存取操作。这两个接口的run()方法会在应用启动完成后被调用,可以在其中实现全局变量的加载和存储。 例如,在一个Spring Boot应用中,可以创建一个MyApplication类,该类实现了CommandLineRunner接口,并注入了一个GlobalVariables对象。在run方法中,调用GlobalVariables对象的loadGlobalVariables()方法,从数据库中加载全局变量并存储到全局Map中。具体代码可以如下所示: ```java @SpringBootApplication public class MyApplication implements CommandLineRunner { @Autowired private GlobalVariables globalVariables; @Override public void run(String... args) throws Exception { globalVariables.loadGlobalVariables(); } public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } ``` 通过实现CommandLineRunner或ApplicationRunner接口,并在run()方法中加载全局变量,可以在Spring Boot应用启动后进行全局变量的存取操作。123 #### 引用[.reference_title] - *1* *2* *3* [说说如何在SpringBoot中启动加载全局变量](https://blog.csdn.net/weixin_42559574/article/details/130073604)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值