JAVA学习之路遇到的报错信息以及解决方法(持续更新中)

2023-10-29

                                  希望本篇文章对你有所帮助  

文章目录

==================================================================================================

1. web项目启动发现错误:Artifact website:war exploded: Error during artifact deployment. See server log for details.


在这里插入图片描述
当你在发布WEB项目的时候,出现了这个错误。此时你可以先去查看其他博主或者网上查询相关的解决方案,如果还是不能解决问题,那么就试试此方法;


在这里插入图片描述
在这里插入图片描述
否则就可能是缺少jar 包,详情看10 ;


2. 进行文件上传时出现错误: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException

出现这种情况,可能是tomcat 服务器的lib 目录下没有
在这里插入图片描述
在tomcat 服务器下加入这两个jar 包就能解决了;


3. 使用idea 连接数据库时,发生错误:No appropriate protocol (protocol is disabled or cipher suites are inappropr

找到JDK安装的位置,然后进入
在这里插入图片描述
将jdk.tls.disabledAlgorithms=…;中的SSLv3,TLSvl去掉即可
在这里插入图片描述


4. 进行邮件发送测试的过程中报错:java.lang.ClassNotFoundException: javax.mail.MessagingException

这个原因是tomcat 的lib 目录下缺少相应的jar包,补上即可;
在这里插入图片描述


5. 使用mysql驱动时发现: Loading class com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is ......

这个问题是 使用了新的mysql8.xx驱动包,但驱动声明不是最新的:
DriverClassName 从 “com.mysql.jdbc.Driver” 换成 “com.mysql.cj.jdbc.Driver” 即可;

在这里插入图片描述


6. 使用Mybatis时报错 Could not find resource mybatis-config.xml,原因可能是因为我们的mybatis-config.xml 不是存放在resources目录下,那么需要在pom.xml 中配置:

<!--    如果一些xml、properties等并不是卸载resources中,那么他们不会被打包进target中,需要在此处设置-->
<!--    如果还是保存说找不到,需要clean 再install一下-->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>


7. 使用properties 文件配置mybatis dataSources 出错:Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: ${driver}

在mybaits-config.xml 缺少 引入properties 的配置

<configuration>
    <!--导入properties文件-->
    <properties resource="db.properties"/>


8. 使用idea或者mybatis 等连接mysql 式报错:Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

  • 可能配置信息写错了
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/mysql_mybatis?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8useSSL=true
username=root
password=cqmcx
<dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${passowrd}"/>
            </dataSource>

  • 可能是因为端口号3306 被占用

在这里插入图片描述


9. 连接mysql 数据库时如果报错 :com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

可能是 数据库停止服务了,可以尝试用Navicat premium 软件连接:
在这里插入图片描述
说明我们的数据库服务确实是关闭了,这个时候:
在这里插入图片描述


10. 找不到相应的xml 文件 :Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/stx/dao/UserMapper.xml,这个可以看我的第6 个配置,如果按6 配置好了,还是报这个问题,就说明还是没有导出,此时则需要 :

在这里插入图片描述


11. 在使用spring AOP 时,报错:Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [beans.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot resolve reference to bean 'pointcut' while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pointcut': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

可能是因为项目中缺少包:

 <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.4</version>
        </dependency>

12. 在使用纯注解AOP下报错:org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract int com.chenxingen.Service.UserService.search();可能是使用了环绕通知的 切入点方法存在返回值,那么我们就可以设置一个Object类型返回值

@Around("pointcut()")
    public Object around(ProceedingJoinPoint jp) throws Throwable {
        ......
        return Object ;
    }

13. 在使用properties文件配置mybatis 数据源时报错: Cause: java.lang.ClassNotFoundException: Cannot find class: ${driver} ..,考虑是否是因为我们没有使用 < properties resource="db.properties"/> 来引入文件


14. 在进行spring - mybatis 整合的时候报错:org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]

可能是由于没有导入 mysql 驱动jar包

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

15. 在进行spring-mybatis 整合的时候报错:Access denied for user ‘admin‘@‘localhost‘ (using password: YES),是因为这个错误是因为在jdbc属性文件中起名username会和windows系统冲突,将username换成其他的即可

修改db.properties

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mysql_mybatis?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=true
user=root
password=cqmcx

 <!--配置数据源:数据源有非常多,可以使用第三方的,也可使使用Spring的-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${user}"/>
        <property name="password" value="${password}"/>
    </bean>

16. 在进行springmvc 开发过程中,出现一切正常但就是访问页面404

如果jar包存在,显示无法输出,就在IDEA的项目发布中,添加lib依赖!
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
重启tomcat;


17. 在进行ssm 整合的时候:org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常

跟16 的解决方式一样


18. 在进行springboot 项目开发过程中:Identify and stop the process that’s listening on port 8080 or configure …

在这里插入图片描述


19. 在进行spring项目开发的过程中:Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError

这个原因可能是Spring在实例化这个类的时候,先执行静态块,再加载autowire注解,所以此时我的对象里是没有值的,此时某个类还未实例化(检查是否已加注解),故而报了这个空指针错误
如果使用的是2.7.3版本,使用了Date 这种过时的,也可能报空指针异常,请注意!!!!


20. 在进行springboot 整合shiro 过程中:Wildcard string cannot be null or empty. Make sure permission strings are properly formatted.] with root cause

在shiro添加权限的方法addStringPermission()中,集合中的元素不能是空值!


21. 在springboot2.7.3集成swagger 3.0.0 报错:Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

在application.yml

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

22. 在使用mybatisplus的TableId注解是发生错误:Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'users.PRIMARY'

是因为我们写的时候,用的是long,而不是Long

//表示其对应数据库中的主键
  @TableId(type=IdType.ID_WORKER)
  private Long id; //正确
  
	//@TableId(type=IdType.ID_WORKER)
 // private long id; //错误

23. 使用mybatis-plus 3.0.5代码生成器报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/velocity/context/Context

缺少了org/apache/commons/lang/exception/NestableRuntimeException所以要手动添加这个依赖

 <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.0</version>
        </dependency>

24. 通过maven 来构建springboot项目时,代码没有错误,但是不能进行注入

是需要在测试启动类上加上两个注解即可

@RunWith(SpringRunner.class)
@SpringBootTest

25.SpringCloud 使用Eureka 时候,报错No spring.config.import set

spring cloud 2020默认禁用bootstrap。需要加入bootstrap依赖。

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>

26.添加负载均衡Ribbon后,启动springboot时 [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class] cannot be opened because it does not exist报错

ServerPropertiesAutoConfiguration,在springboot 2.x.x 以后移除了,当springboot>=2.x.x ,其他jar包加载 涉及到ServerPropertiesAutoConfiguration 就会报错了,添加如下依赖

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
            <version>2.2.9.RELEASE</version>
        </dependency>

如果出现错误 java.lang.IllegalStateException : No instances available for XXX
需要将

<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-ribbon</artifactId>-->
<!--            <version>1.4.7.RELEASE</version>-->
<!--        </dependency>-->

去掉,因为两者出现冲突了


如果依然不能解决问题,建议:
eureka服务端官方推荐用依赖包:spring-cloud-starter-netflix-eureka-server,取代已经过时的spring-cloud-starter-eureka-server。
eureka客户端官方推荐使用依赖包:spring-cloud-starter-netflix-eureka-client,已经内置ribbon支持。取代已经过时的spring-cloud-starter-eureka。并且无需再导入ribbon依赖包。
这样从源头解了:“ServerPropertiesAutoConfiguration.class] cannot be opened because it does not exist” 和 "no instances available…"两个报错。


27. com.mysql.cj.exceptions.CJCommunicationsException: Communications link failu

可能是mysql 服务挂了,重新启动一下应该就ok了;
在这里插入图片描述

28. springboot 2.7 之后因为循环依赖导致项目启动报错

在这里插入图片描述
可以配置application.yml

spring:
   main:
     allow-circular-references: true

恢复正常


29. Spring Cloud Zuul网关启动成功,报HTTP Status 500 – Internal Server Error错误

在这里插入图片描述
zuul与springboot的版本不匹配导致的冲突,同时需要注意springboot 与springcloud 版本要一致;
在这里插入图片描述
2.2.10.RELEASE版本的zuul需要配置2.4.x的springboot版本,所以我们的springcloud 也需要修改为2020.0.x 版本的;


30. springboot 打jar 包报错Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0

在这里插入图片描述


31.项目的jar包不是在maven服务器上能够下载的,那么需要将这样的包放在项目的lib目录下,不过这样会导致maven打包时找不到包,报错

在这里插入图片描述

 <dependency>
            <groupId>e-iceblue</groupId>
            <artifactId>spire.pdf</artifactId>
            <version>4.10.2</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/lib/spire.pdf-4.10.2.jar</systemPath>
        </dependency>

即可;


32.打包时跳过项目测试用例

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!--跳过项目运行测试用例-->
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.json</include>
                    <include>**/*.js</include>
                    <include>**/*.pdf</include>
                </includes>
            </resource>
        </resources>

    </build>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JAVA学习之路遇到的报错信息以及解决方法(持续更新中) 的相关文章

随机推荐

  • 通过自动回复机器人学Mybatis—基础版

    曲不为直终必弯 养狼当犬看家难 墨染鸬鹚黑不久 粉刷乌鸦白不坚 蜜饯黄莲终清苦 强摘瓜果不能甜 好事总得善人做 那有凡人做神仙 准备工作 JSP JSTL EL JS JQUERY Servlet JavaBean JDBC Mybatis
  • qt学习——基本使用、对象树、按钮、信号与槽

    初识qt qt qt命名规范以及相关快捷键的使用 QPushButton 对象树 点击按钮关闭窗口 信号和槽 标准的信号和槽 自定义信号和槽 带参数的自定义信号和槽传参以及函数的二义性问题 信号和槽的拓展 qt4的信号与槽 QDebug的输
  • 修改 Flutter 中字体的大小和颜色

    import package flutter material dart void main gt runApp MyApp class MyApp extends StatelessWidget This widget is the ro
  • rk3568can设置异常

    板子 rk3568 平台 android11 1 问题描述 设备树中can的配置 can1 can fe580000 compatible rockchip canfd 1 0 reg lt 0x0 0xfe580000 0x0 0x100
  • 【机器学习】浙工商机器学习实验指导(一)

    文章目录 一 实验一 线性回归算法实验 1 1 算法引入 1 2 模拟数据实验 1 3 Boston 数据实验 二 实验二 SVM算法 2 1 算法介绍 2 2 鸢尾花数据实验 三 实验三 集成学习一 3 1 简单介绍 3 2 Breast
  • 在LATEX中优雅地插入MATLAB代码

    利用MATLAB的mcode宏包 即可实现三种插入MATLAB的方式 行内代码 行间代码块 以文件形式插入 mcode包的下载地址 及官方说明 mcode帮助文档 另外Latex中运行代码块 需要lstlisting包 lstlisting
  • 二叉树相关

    二叉树的种类 在我们解题过程中二叉树有两种主要的形式 满二叉树和完全二叉树 满二叉树 满二叉树 如果一棵二叉树只有度为0的结点和度为2的结点 并且度为0的结点在同一层上 则这棵二叉树为满二叉树 如图所示 这棵二叉树为满二叉树 也可以说深度为
  • 【Leetcode】16. 最接近的三数之和

    题目描述 给定一个包括 n 个整数的数组 nums 和 一个目标值 target 找出 nums 中的三个整数 使得它们的和与 target 最接近 返回这三个数的和 假定每组输入只存在唯一答案 题解 解法和 Leetcode 15 三数之
  • 学习了解可能的影响变量,例如收入和体育锻炼对……的影响

    心理健康 资料来源 心理健康正日益成为一个传统上被掩盖的话题 我们已经开始理解心理健康对生产力 总体健康 人际关系和身体健康的影响 并将更多的注意力放在心理健康上 甚至雇主也开始更加重视提供工作环境和条件 以保持员工尽可能快乐和健康 而先进
  • postman中发送post请求保存数据到数据库中文乱码问题

    postman中发送post请求保存数据到数据库中文乱码 postman 以为是header中的问题 加上这俩问题并未解决 以为是数据库的问题 改成这个也没解决 后台打印也没问题 book Book id null type 类别111 n
  • Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could

    Failed to configure a DataSource url attribute is not specified and no embedded datasource could be configured Reason Fa
  • SpringSecurity授权

    目录 一 RABC的介绍 二 权限表设计 三 编写权限控制方法 1 mapper接口 2 映射文件 3 修改认证逻辑 四 配置类访问资源 五 自定义访问控制逻辑 1 自定义 2 配置类 六 注解设置访问控制 1 Secured 1 在配置了
  • Status Code:200 OK (from disk cache)和304的区别,以及怎么禁止缓存

    有时候缓存是 200 OK from disk cache 有时候会是 304 看运维是否移除了 Entity Tag 移除了 就总是 200 OK from cache 没有移除 就两者交替出现 他们两个的区别是 200 OK from
  • C++中rand() 函数的用法

    C 中rand 函数的用法 1 rand 不需要参数 它会返回一个从0到最大随机数的任意整数 最大随机数的大小通常是固定的一个大整数 2 如果你要产生0 99这100个整数中的一个随机整数 可以表达为 int num rand 100
  • ajax的三种方法以及ajax概念

    目录 Ajax技术主要包括 1 客户端脚本语言 JavaScript 2 异步数据获取技术 XMLHttpRequest 3 数据交换和操作技术 XML和XSTL 4 动态显示和交互技术DOM及基于标准的表示技术XHTML和CSS等 aja
  • elasticsearch 启动报错 Exception in thread "main" java.nio.file.AccessDeniedException:

    系统 操作centos7 虚拟机 bin elasticsearch 启动报错 es1 es1 software elasticsearch 6 3 1 bin elasticsearch Exception in thread main
  • 中文版LLaMA:Chinese-LLaMA-Alpaca

    GitHub GitHub ymcui Chinese LLaMA Alpaca 中文LLaMA Alpaca大语言模型 本地CPU GPU训练部署 Chinese LLaMA Alpaca LLMs 以ChatGPT GPT 4等为代表的
  • Uncaught SyntaxError: Unexpected token ")"

    碰到一个很难排查的错误 记得以前处理过 光看报错信息 无法确定报错位置 从网上搜到解决方案 这个一般是对页面操作发生的错误 静态页面不报错 把源代码中的javascript void 改为javascript void 0 括号中添加一个0
  • 在Easy Samples中使用AvaloniaUI进行多平台UI编码——第1部分——AvaloniaUI构建块

    目录 介绍 为什么Avalonia会大受欢迎 Avalonia的一些缺点 Web和Xamarin框架在多平台开发中的缺点 你可以在这篇文章中找到什么 如何阅读这篇文章 使用Visual Studio 2019创建和运行简单的Avalon项目
  • JAVA学习之路遇到的报错信息以及解决方法(持续更新中)

    希望本篇文章对你有所帮助 文章目录 1 web项目启动发现错误 Artifact website war exploded Error during artifact deployment See server log for detail