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

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

文章目录

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

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>
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Java开发经常会遇到各种报错,以下是一些常见的报错及其解决办法: 1. NullPointerException(空指针异常) 这个异常通常是因为代码使用了一个空的对象引用,解决方法是检查代码是否有空的对象引用,或者在使用对象引用之前先进行判空操作。 2. ClassNotFoundException(找不到类异常) 这个异常通常是因为代码使用了一个不存在的类,解决方法是检查类路径是否正确,或者是否缺少了相应的jar包。 3. NoSuchMethodException(找不到方法异常) 这个异常通常是因为代码使用了一个不存在的方法解决方法是检查方法名是否正确,或者是否传递了正确的参数。 4. ArrayIndexOutOfBoundsException(数组下标越界异常) 这个异常通常是因为代码使用了一个不存在的数组下标,解决方法是检查数组下标是否越界,或者是否在使用数组之前先进行了初始化。 5. SQLException(SQL异常) 这个异常通常是因为代码使用了不正确的SQL语句或参数,解决方法是检查SQL语句是否正确,或者是否传递了正确的参数。 6. IOException(输入输出异常) 这个异常通常是因为代码使用了不正确的输入输出操作,解决方法是检查输入输出操作是否正确,或者是否在使用输入输出之前先进行了初始化。 以上是一些常见的Java报错及其解决方法,当然还有其他的报错类型,需要开发人员自己不断学习和积累经验来解决

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈行恩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值