问答

一个spring mvc项目,异常信息直接输出到页面上,而控制台日志里

作者:admin 2021-09-24 我要评论

问题描述 一个spring mvc项目,异常信息直接输出到页面上,而控制台日志里面却没有打印异常堆栈信息? 如下图: 控制台日志却不打印异常信息 问题出现的环境背景...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

问题描述

一个spring mvc项目,异常信息直接输出到页面上,而控制台日志里面却没有打印异常堆栈信息?
如下图:
image.png

控制台日志却不打印异常信息
image.png

问题出现的环境背景及自己尝试过哪些方法

背景:
spring mvc项目,spring版本4.3.25,日志组件用的是slf4J+logback

尝试过的方法:
1.一开始查阅资料,以为是日志组件的问题,在web.xml文件中配置了 logback.xml的监听器,不起作用

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xmlns="http://java.sun.com/xml/ns/javaee"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     id="WebApp_ID" version="3.0">


<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:META-INF/spring/spring-config.xml</param-value>
</context-param>

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>manage-web.all.root</param-value>
</context-param>


<!-- Processes application requests -->
<servlet>
    <servlet-name>springMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:META-INF/spring/springMVC-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>



<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>

你期待的结果是什么?实际看到的错误信息又是什么?

###

检查一下你的logback日志配置文件,看看error信息有没有输出配置到console.~~~~

###

你的logback配置文件长啥样?

###

把你项目的 slf4J + logback 的配置贴出来看看

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 一个spring mvc项目,异常信息直接输出

    一个spring mvc项目,异常信息直接输出

  • idea设置了热部署,为什么每次修改java

    idea设置了热部署,为什么每次修改java

  • 新手入门go开发框架gin,代码与教程中

    新手入门go开发框架gin,代码与教程中

  • 怎么把方法名作为参数传入呢?

    怎么把方法名作为参数传入呢?

腾讯云代理商
海外云服务器