错误笔记

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:

错误原因:

电脑上的mysql版本高,而项目中的mysql-java驱动版本过低,二者不匹配。

解决办法:

  1. 升级jdbc驱动类:com.mysql.jdbc.Driver 改成 com.mysql.cj.jdbc.Driver

  2. 升级对应的jdbc驱动,mysql8.x使用以下版本驱动即可

    <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>8.0.19</version>
    </dependency>
    

java.sql.SQLException: com.mysql.cj.jdbc.Driver

错误原因

mysql连接驱动依赖的版本不匹配问题,一般出现在使用低版本连接驱动连接高版本mysql情况下

解决办法

升级对应的jdbc驱动,mysql8.x使用以下版本驱动即可

		<dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.19</version>
    </dependency>

org.apache.maven.plugin.war.WarMojo

报错信息:

[WARNING] Error injecting: org.apache.maven.plugin.war.WarMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:
 
1) Error injecting constructor, java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties
  at org.apache.maven.plugin.war.WarMojo.<init>(Unknown Source)
  while locating org.apache.maven.plugin.war.WarMojo
 
1 error

错误原因

缺少 maven-war-plugin 插件

解决办法

在pom.xml里,<project> </project>中添加如下插件

<build>
    <!-- To define the plugin version in your parent POM -->
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.3.1</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <!-- To use the plugin goals in your POM or parent POM -->
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.1</version>
      </plugin>
    </plugins>
</build>

org.springframework.beans.factory.BeanCreationException

异常描述

在学习黑马《传智健康》项目的第二天,项目配置完成并配置完成后,启动 Tomcat 服务器,报出如下错误:

image-20220825181145310

异常原因1

通过观察上图中被标记出来的异常信息,咱们可以知道

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘XXX’

此异常,为:注入 bean 失败异常。

说白了,出现这个异常,就是找不到对应的 bean 啦!能够导致 bean 注入失败的原因包括以下几种,但不限于这几种:

  • 对应的 bean 没有添加注解;
  • 对应的 bean 添加注解错误,例如将 Spring 的@Service错选成 dubbo 的;
  • 选择错误的自动注入方法等。

解决方法

既然知道了出现此异常的原因,那我们就回过头来,去看看对应的 Bean 声明,观察后发现注入 CheckItemServiceImpl 的代码为:

@Service(interfaceClass = CheckItemService.class)//注意这里使用dubbo注册的Service
@Transactional
public class CheckItemServiceImpl implements CheckItemService {

    public CheckItemDao checkItemDao;
    @Override
    public void add(CheckItem checkItem) {
        checkItemDao.add(checkItem);
    }
}

CheckItemDao缺失**@Autowired**自动注入,添加上去即可

异常原因2

jdk版本不对

解决办法

我把jdk版本从18降回到jdk1.8,好了。


请求路径问题

异常描述

请求路径带了当前page路径

image-20220826105204020

错误原因

是因为是前端html发送ajax请求时,少写了/的相对路径

axios.post("checkitem/findPage.do",param).then((response)=>{
                        if (response.data.flag){
                            //为模型数据赋值,基于VUE的双向绑定展示到页面
                            this.dataList = response.data.rows;
                            this.pagination.total = response.data.total;
                        }
                    })

解决办法

应在checkitem/findPage.do前面添加/checkitem/findPage.do

axios.post("/checkitem/findPage.do",param).then((response)=>{
                        if (response.data.flag){
                            //为模型数据赋值,基于VUE的双向绑定展示到页面
                            this.dataList = response.data.rows;
                            this.pagination.total = response.data.total;
                        }
                    })

image-20220826105743210


org.springframework.beans.factory.BeanCreationException: Error creating bean with name /applicationContext-jobs.xml]: Invocation of init method failed; nested exception is java.text.ParseException: Unexpected character: >

错误原因:

在做项目练习的时候,使用Quartz调度器时,一直报,bean初始化错误,各种百度,以为是导入的Spring版本不对,或者是Quartz版本升级,配置方式不同,结果都不是

image-20220901172416617

解决办法:

在耽误了半天时间,终于找出了原因,其实一开始,报错log就给了我提示,我一直没看明白

image-20220901172618587

其实原因是,我在修改定时器,生效频率时一不小心,多了个>尖头

image-20220901172806170

**注意:**以后凡是遇到创建bean错误的时候,一点要注意看log,和检查配置文件。


java.lang.IllegalStateException: Zip File is closed

异常描述:

在访问excel文件的时候,出现以下异常

image-20220907151413828

错误原因:

当访问时,使用绝对路径可以读出excel文件的内容,而借助其他方式读出文件时出现错误,可能是由于路径中出现中文乱码

解决办法:

将路径转换格式:

try {
  path = URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e) {
  e.printStackTrace();
}

MyBatis根据日期查询问题

异常描述:

在项目中根据日期查询数据,MyBatis总是查询不到

image-20220914180040132

实际上如果是把这条SQL语法,放到数据库管理工具可以查出数据

image-20220914180218330

问题原因:

我们把关注点放到这句话上

Parameters: 2022-09-15 00:00:00.0(Timestamp)

以及sql执行语句

<select id="findByOrderDate" parameterType="date" resultType="com.itheima.pojo.OrderSetting">
        select *
        from t_ordersetting
        where orderDate = #{orderDate}
    </select>

从上面可以看出,数据库的字段是date类型,通过mybatis传入timestamp类型参数,类型不同是不能进行等于比较的,所以返回的是null。

解决办法:

给sql语句接受参数出指定jdbcType=DATE

<!--根据日期查询预约设置信息-->
    <select id="findByOrderDate" parameterType="date" resultType="com.itheima.pojo.OrderSetting">
        select *
        from t_ordersetting
        where orderDate = #{orderDate,jdbcType=DATE}
    </select>

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' available

错误原因:

bean未定义错误,在集成springSecurity的时候,,我在web.xml中添加了

<!--委派过滤器,用于整合其他框架-->
<filter>
   <!--
      DelegatingFilterProxy用于整合第三方框架
      整合Spring Security时过滤器的名称必须为springSecurityFilterChain,
	  否则会抛出NoSuchBeanDefinitionException异常
    -->
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

但是提示,找不到springSecurityFilterChain对象,我检查了springSecurityFilterChain拼写没问题,是因为没有在web.xml,中配置springSecurity所需要的spring-security.xml

解决办法:

需要在web.xml的DispatcherServlet节点下,添加spring-security.xml配置文件,并完善spring-security.xml 相关配置信息。


uncategorized SQLException; SQL state [HY000]; error code [1525]; Incorrect DATE value: '2022.02.31'; nested exception is java.sql.SQLException: Incorrect DATE value: '2022.02.31'

问题背景:在传智健康第10天课程,引入ECharts,统计会员信息的时候,需要查询所在月份的会员数时,根据老师的讲课教程,默认传入日期的最大时间,31天。

报错信息:

image-20221107191252608

错误原因:

在MySQL 5+版本不会报错,但是在MySQL 8+版本上会报错。原因是MySQL 8+版本增加了日期校验,2月31显然是不合法的,因此报错。

//根据月份统计会员数量
public List<Integer> findMemberCountByMonth(List<String> month) {
  List<Integer> list = new ArrayList<>();
  for(String m : month){
    m = m + ".31";//格式:2019.04.31
    Integer count = memberDao.findMemberCountBeforeDate(m);
    list.add(count);
  }
  return list;
}

解决办法:

通过获取日历对象,获取所在月份的最后一天,即可。

@Override
    public List<Integer> findMemberCountByMonth(List<String> month) {
        Calendar calendar = Calendar.getInstance();
        List<Integer> list = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(String m : month){
            String[] split = m.split("\\.");
            //设置年
            calendar.set(Calendar.YEAR, Integer.parseInt(split[0]));
            //设置月
            calendar.set(Calendar.MONTH, Integer.parseInt(split[1]));
            //设置月的最后一天
            calendar.set(Calendar.DAY_OF_MONTH, 0);
            String date = sdf.format(calendar.getTime());
            Integer count = memberDao.findMemberCountBeforeDate(date);
            list.add(count);
        }
        return list;
    }

net.sf.jasperreports.engine.JRException: java.io.IOException: The byte array is not a recognized imageformat.

问题背景:在传智健康第12天课程,编写JaspersoftDemo,引入课件资源提供的demo.jrxml,编译准备生成test.pdf文件时,报错。

报错信息:

image-20221109153159306

一开始我,我在疑惑,demo.jrxml中,老师上课时,并未设计image元素在pdf文件上。

直至,我查看了,demo.jrxml文件,发现其中引用了image元素。

image-20221109153424348

解决办法:

由于传智官网,采用了https协议,课件中提供的demo.jrxml 文件,image元素无法获取到图片资源,只要将图上image资源的URL改为下面地址即可

https://www.itcast.cn/2018czgw/images/logo.png
<!--或者-->
https://www.itcast.cn/2018czgw/images/logo2.png
Loading...