Spring学习中遇到的异常


MySQL异常

SQL异常

在这里插入图片描述

  • 错误原因:SQL时区没有设置,这个是因为springboot默认使用的MySQL是8.0以上的版本,我们使用的是5.0的版本。
  • 解决方法:增加一个时区配置:serverTimezone=UTC
spring:
  datasource:
    username: root
    password: 123456
    #假如时区报错了,就增加一个时区配置:serverTimezone=UTC
    url: jdbc:mysql://localhost:3306/mybatisdb?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
    driver-class-name: com.mysql.cj.jdbc.Driver

springboot整合Druid时出现的异常

由于 /** 与 /* 造成的异常

在基于springBoot框架整合Druid时,在DruidConfig配置类配置对应的ServletRegistrationBean时,路径不小心填写了/druid/**,导致了本地访问时,无法跳转DRUID的监控登陆页面而是报了404错误,当后来修改为/druid/*时,则可以正常访问login页面。
/druid/**

 ServletRegistrationBean bean = 
 new ServletRegistrationBean(new StatViewServlet(), "/druid/**");

在这里插入图片描述

 ServletRegistrationBean bean = 
 new ServletRegistrationBean(new StatViewServlet(), "/druid/*");

在这里插入图片描述
/*/**的区别:

/*是指代下面的一级路径		不包括其子目录下的资源			
/**是指代的下面的全部路径	包括其子目录的下的资源。

shiro框架

出现NoClassDefFoundError

在这里插入图片描述
出现这样的错误是因为pom.xml里缺少了一个依赖。
解决方法是添加

<dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>

修改后的pom.xml文件是

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springboot-08-shiro</artifactId>
        <groupId>com.zhu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hello-shiro</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.4.1</version>
        </dependency>
        <!-- Shiro uses SLF4J for logging.  We'll use the 'simple' binding
             in this example app.  See http://www.slf4j.org for more info. -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.21</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.21</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>

修改过后重新启动,输出结果为;
在这里插入图片描述

StackOverflowError

java.lang.StackOverflowError: null
意思是:出现栈内存溢出的常见原因有2个:

  1. 函数递归调用层次过深,每调用一次,函数的参数、局部变量等信息就压一次栈,并且没有及时出栈。
  2. 局部静态变量体积太大
    在这里插入图片描述
    错误原因是,controller接口自己调用了自己,因此形成了死循环,直至内存溢出。
    在这里插入图片描述
    解决方法是:
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值