1.status=404 Whitelabel Error Page

Whitelabel Error Page

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

Mon Nov 13 16:37:27 CST 2017
There was an unexpected error (type=Not Found, status=404).
No message available

刚开始学习,按照别人写的HelloWorld进行配置后,运行报出以上错误,检查Path后没有问题。

最后搜索发现问题出在 @SpringBootApplication的扫描范围:

 @SpringBootApplication的同级包及其子包会被扫描,因此Application需要放在整个系统的主路径下。

同时@RequestMapping(value="/listPort",method=RequestMethod.POST)这个也要写对,我将 value变为了name导致一直扫描不到。

同时不用使用项目名: http://127.0.0.1:8080/[annonationPath]

如果要加,则配置文件中添加 server.context-path=/项目名

如果使用thymeleaf的templates,出现错误则注意pom.xml中是否有加入thymeleaf依赖:

      <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2. @SpringBootApplication、SpringApplication、ModelAndView、EmbeddedServletContainerCustomizer多个类无法引入问题

刚开始使用springBoot的2.0.0 M6测试版,但引入有有些类或注解加载不进去(EmbeddedServletContainerCustomizer),可能大版本中有些类注解有变化所致,最后返回到1.5.8当前正式版后,出现以上错误,怎么Maven Update Project 都无法解决。最后网上有人说是jar包冲突导致。

直接删除掉Maven仓库中的org.springFramework,从新更新工程,让从新下载即可。

3. springboot 报错     没有主清单属性

打包成jar文件直接运行报错。缺少主驱动程序,

  参照:https://blog.csdn.net/u010429286/article/details/79085212

添加 maven-plugin驱动。

      <plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.jetty.mac.MacJetty.App</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

然后重新

>mvn  clean package

>java -jar   ****.jar

4.元素类型 "link" 必须由匹配的结束标记 "</link>" 终止

springboot 中引入thymeleaf,但是在页面上<link>没有结束标签,导致。

添加依赖:

<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>

在application.properties中修改:

spring.thymeleaf.mode=HTML5
->
spring.thymeleaf.mode=LEGACYHTML5

5. static静态文件访问不到404

在配置文件application.properties中添加static的资源访问

spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/

6.org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe not public?

在上传文件时,前台显示404,后端报错。

对于springboot的404并非一定是404没有找到资源地址,而是出错后不知怎么处理,找不到对应的error page 而报出来的404.

在上传文件时,springboot默认是1Mb的上限。同时如果是自己设置的临时路径,需要设置mkdir,要不然找不到文件路径。以上都有可能抛出此类异常

# file
spring.http.multipart.enabled=true
spring.http.multipart.location=file/tmp
spring.http.multipart.resolve-lazily=false
spring.http.multipart.max-file-size=8Mb
    /**
* 临时文件存放地址设置
* @return
*/
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
String location = System.getProperty("user.dir") + "/file/tmp";
File tmpFile = new File(location);
if (!tmpFile.exists()) {
tmpFile.mkdirs();
}
factory.setLocation(location);
return factory.createMultipartConfig();
}

文件上传部分代码:

    /**
* 文件读入
*/
@RequestMapping("/file/upload")
@ResponseBody
public RespResult uploadFile(@RequestParam("file")MultipartFile file,Model model) {

7. Caused by: org.xml.sax.SAXParseException: 前言中不允许有内容

springboot+mybatis,运行启动时,注意查看于mybatis相关的配置文件和java文件。如果格式都正确,则需要查看application.properties,因为db的信息就在这里。

@PropertySource(value="classpath:./applicationTest.properties",encoding="UTF-8")

8. SpingBoot:Unregistering JMX-exposed beans on shutdown

原因为:SpringBoot内置Tomcat没有正常启动,在pom.xml 中添加:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

另一种情况是有jar下载失败

参见:https://www.cnblogs.com/QQ931697811/p/6707740.html

9. Failed to start component [StandardEngine[Tomcat]]

因mvn依赖中的tomcat和servlet-api发生冲突导致,需要移除其中一个,或者在依赖中剔除掉Web 依赖。

注意在servelt-api3.0版本后变为  javax.servlet-api.同时在多个项目关联时,有时在项目互相引用时会出现冲突,需要引用jar包解决。即常见的 项目中运行报错,打包后正常。

<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>

9. AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;

springmvc和springboot包之间的冲突,两者只能选择一个。

springBoot异常处理的更多相关文章

  1. SpringBoot异常处理统一封装我来做-使用篇

    SpringBoot异常处理统一封装我来做-使用篇 简介 重复功能我来写.在 SpringBoot 项目里都有全局异常处理以及返回包装等,返回前端是带上succ.code.msg.data等字段.单个 ...

  2. Springboot异常处理和自定义错误页面

    1.异常来源 要处理程序发生的异常,首先需要知道异常来自哪里? 1.前端错误的的请求路径,会使得程序发生4xx错误,最常见的就是404,Springboot默认当发生这种错误的请求路径,pc端响应的页 ...

  3. SpringBoot异常处理(二)

    参数校验机制 JSR-303 Hibernate 参数接收方式: URL路径中的参数 {id} (@PathVariable(name="id") int-whatever) UR ...

  4. SpringBoot 异常处理

    异常处理最佳实践 根据我的工作经历来看,我主要遵循以下几点: 尽量不要在代码中写try...catch.finally把异常吃掉. 异常要尽量直观,防止被他人误解 将异常分为以下几类,业务异常,登录状 ...

  5. 【使用篇二】SpringBoot异常处理(9)

    异常的处理方式有多种: 自定义错误页面 @ExceptionHandler注解 @ControllerAdvice+@ExceptionHandler注解 配置SimpleMappingExcepti ...

  6. SpringBoot学习15:springboot异常处理方式5(通过实现HandlerExceptionResolver类)

    修改异常处理方式4中的全局异常处理controller package com.bjsxt.exception; import org.springframework.context.annotati ...

  7. SpringBoot学习14:springboot异常处理方式4(使用SimpleMappingExceptionResolver处理异常)

    修改异常处理方法3中的全局异常处理Controller即可 package bjsxt.exception; import org.springframework.context.annotation ...

  8. SpringBoot学习13:springboot异常处理方式3(使用@ControllerAdvice+@ExceptionHandle注解)

    问题:使用@ExceptionHandle注解需要在每一个controller代码里面都添加异常处理,会咋成代码冗余 解决方法:新建一个全局异常处理类,添加@ControllerAdvice注解即可 ...

  9. SpringBoot学习12:springboot异常处理方式2(使用@ExceptionHandle注解)

    1.编写controller package com.bjsxt.controller; import org.springframework.stereotype.Controller; impor ...

随机推荐

  1. day20 python sys os time json pickl 正则

    字符组 : [字符组] 在同一个位置可能出现的各种字符组成了一个字符组,在正则表达式中用[]表示 字符分为很多类,比如数字.字母.标点等等. 假如你现在要求一个位置....9这10个数之一. 量词 几 ...

  2. smarty中调用php内置函数

    http://blog.csdn.net/clevercode/article/details/50373633

  3. [Python] 中文路径和中文文本文件乱码问题

    情景: Python首先读取名为log.txt的文本文件, 其中包含有文件名相对路径信息filename. 随后Python调用shutil.copy2(src, dst)对该filename文件进行 ...

  4. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境

    1.资源准备 最近,在VmwareStation 10虚拟机上,基于CentOS5.4安装Oracle 11g RAC,并把过程记录下来.刚开始时,是基于CentOS 6.4安装Oracle 11g ...

  5. 设计模式初学者笔记:Abstract Factory模式

    首先啰嗦下创建迷宫所用的Room类.这个类并不直接保存Room四周的构造,而是通过MapSite* _sides[4]这个私有数组成员指向Room四周的构造.那么什么时候将四周构造直接放在Room中, ...

  6. 【ActiveMQ入门-8】ActiveMQ学习-与Spring集成

    概述: 下面将介绍如何在Spring下集成ActiveMQ. 消费者:同步接收: 目的地:topic 环境: 主要包括4个文件: HelloSender.java: JMSTest.java: Pro ...

  7. Nginx+tomcat+redis实现session共享

    Nginx+tomcat+redis实现session共享 1,安装nginx,使用yum -y install nginx 这是epel源中的,需要安装epel源. 2,配置nginx. 在ngin ...

  8. css position 和 块级/行内元素解释

    一.position 属性: static:元素框正常生成.块级元素生成一个矩形框,作为文档流的一部分,行内元素则会创建一个或多个行框,置于其父元素中. relative:元素框偏移某个距离.元素仍保 ...

  9. DOM节点的增删改查

    在开始展开DOM操作前,首先需要构建一棵DOM树. <!DOCTYPE html> <html lang="en"> <head> <me ...

  10. 在ie6下的png图片的兼容问题

    png图片在ie6下是这样的: 正确样式: 这样解决: html代码: <body> <div class="gys"></div> </ ...