编程常见的bug总结

  1. 一般由springframework.beans.factoty.xml.XmlBeanDefinitionReader.setParaserClass(Ljav/lang/Class)表示程序中有的包导入错误
    1. ApplicationContext act=new ClassPathXmlApplicationContext("applicationContext.xml"); 
    2. 对应的包应该是:import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;其他的包都是错误的。
  2. Cannot publish to a deleted Destination: temp-queue://spring-active-queue; nested exception is javax.jms.InvalidDestinationException: Cannot publish to a deleted Destination: temp-queue://spring-active-queue

    1. 这是由于applicationContext.xml配置文件的配置queue或者Topic的对象时使用了错误的类。
    2. <bean id="destinationQueue" class="org.apache.activemq.command.ActiveMQQueue">  //这里容易出现org.apache.activemq.command.ActiveMQTempQueue这是错误的
      <constructor-arg index="0" value="spring-active-queue"/> </bean>
  3.   An incompatible version [1.2.7] of the Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]:

    1. 原因是tomcat可移植运行库在C:\Windows\System32目录里缺少一个tcnative-1.dll文件

    2. 解决办法: 下载一个tcative-1.dll文件放在syste32文件夹下

    3. 下载地址:http://archive.apache.org/dist/tomcat/tomcat-connectors/native/1.2.14/binaries/

  4. 同一个spring boot工程同时启动两个主类两个端口遇到的问题
    1. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
      2021-05-29 14:37:23.806 ERROR 16136 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :

      ***************************
      APPLICATION FAILED TO START
      ***************************

      Description:

      Web server failed to start. Port 5566 was already in use.

      Action:

      Identify and stop the process that's listening on port 5566 or configure this application to listen on another port.


      Process finished with exit code 0

    2. 提示:我们第二个启动的端口被占用,没错是被第一个服务占用了,这是由于我们在pom.xml文件内加入了惹部署依赖,当我们改变配置文件时,热部署会自动帮我们吧端口号修改为第二个端口号,于是当我们在启动第二个服务时,端口还被第一服务占用,所有报错

    3. 解决办法:将热部署依赖关闭

  5. 网络编程:Cannot send after socket shutdown: socket write error ,写入数据后一定要进行flush(),同时进行结束标志 socket.shutdownOutput();

  6. “Error:(3, 24) java: 程序包org.junit不存在”的3种解决方法
    1. 安装maven,创建maven-archtype-quickstart后,进行junit单元测试时,报出以下错误:
    2. 解决办法:更改Juint的版本号;重新启动idea就可以成功解决:
  7. 网络编程,通信系统-服务端:在接受信息的线程中,使用的while循环,我们在while循环中可以连续创建ObjectInputStream()对象但是不可以连续创建OjectOutputStream()对象,会造成异常
    1. java.io.StreamCorruptedException: invalid type code: AC! 


      public void run() {//这里线程处于运行状态,可以接受和发送消息 while (true){ System.out.println("服务端和"+userName+"客户端保持通信"); try { // 这里只能创建ObjectInputStream,不能创建ObjectOutputStream会造成异常,每次while都创建ObjectOutputStream ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
      //错误的代码,我们需要将ObjectOutputStream()对象的创建防在if语句中,不能放在while语句中 // ObjectOutputStream objectOutputStream
      = new ObjectOutputStream(socket.getOutputStream()); Message message = (Message) objectInputStream.readObject(); // 当用户的的请求信息类型时后去在线用户的列表是 if (message.getMessageText().equals(MessageType.MESSAGE_GET_ONLINE_FRIEND)){ String sender = message.getSender(); Message resMessage = new Message(); String onlineList = ManageClientThread.getOnlineList(); resMessage.setMessageText(MessageType.MESSAGE_RET_ONLINE_FRIEND); resMessage.setGetter(sender); resMessage.setContext(onlineList); ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); objectOutputStream.writeObject(resMessage); System.out.println(sender+"请求了用户列表,成功返回用户列表信息"); }else if(message.getMessageText().equals(MessageType.MESSAGE_CLIENT_EXIT)){//用户请求退出时 String sender = message.getSender(); // 将对应的客户的线程从线程集合中移除 ManageClientThread.remove(sender); socket.close(); System.out.println("用户:"+sender+"成功退出系统"); break; }else if (message.getMessageText().equals(MessageType.MESSAGE_COMM_MESSAGE)){//私聊的信息类型 // 服务器将message转发给Message的getter用户 String sender = message.getSender(); String getter = message.getGetter(); System.out.println(sender+"->"+getter+"说:"+message.getContext()); ObjectOutputStream getterOutputStream = new ObjectOutputStream(ManageClientThread.get(getter).getSocket().getOutputStream()); getterOutputStream.writeObject(message);//如果客户不在可已经信息保存到数据库 }else { System.out.println("其他的信息类型"); } } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } }
  8. Intellij IDEA xxx.properties变成纯文本模式解决方案

    1. 创建某个文件名.propeties。样式为文本格式,非正确的格式,且只有这单独一个文件名是这样的:
    2. 解决方案:

      进入设置,依次点击 File-->settings-->Editor --> File Type

      然后找到 Text-->Registered Patterns,往下翻找到跟这个文件相关名字的xxx.properties,删掉它。

          
  9. springboot使用表单进进行文件上传时,报错:Current request is not a multipart request
    1. 问题:在表单上传数据时,如果含有文件类型的数据,我们需要对表单的 :enctype="multipart/form-data" 进行设置,在表头上加入 enctype="multipart/form-data" 即可
    2. <!DOCTYPE html>
      <html lang="en" xmlns:th="http://www.thymeleaf.org">
      <head>
          <meta charset="UTF-8">
          <title>Title</title>
      </head>
      <body>
      
      <form th:action="@{/doLogin}" method="post" enctype="multipart/form-data">
          头像:<input type="file" name="picture">
          <br>
          生活照:<input type="file" name="photos" multiple>
          <br>
          <input type="submit" th:value="提交">
      </form>
      </body>
      </html>
  10.  


     
  11. 使用mybatis-plus自动生成文件的时候,报下面的错误:
    1. Disconnected from the target VM, address: '127.0.0.1:57082', transport: 'socket'
      Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/velocity/context/Context
      at com.baomidou.mybatisplus.generator.AutoGenerator.execute(AutoGenerator.java:96)
      at com.spek.common.generator.TestMybatisPlus.main(TestMybatisPlus.java:81)
      Caused by: java.lang.ClassNotFoundException: org.apache.velocity.context.Context
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 2 more

      原因是缺少了依赖,解决方案如下:

      pom.xml文件当中加入velocity的依赖

          <!-- 模板引擎 -->
              <dependency>
                  <groupId>org.apache.velocity</groupId>
                  <artifactId>velocity-engine-core</artifactId>
                  <version>2.0</version>
              </dependency>

       

       

       

       

       

posted @ 2021-05-28 19:01  张紫韩  阅读(719)  评论(1编辑  收藏  举报