Java后端之bug奋斗历史(1)

50 阅读8分钟

做为一名程序猿,我们不是在改bug就是在写bug的路上,仅以此记录曾经的bug

1.1 Could not find action or result

 

1.1.1 异常信息

2017-11-13 17:02:54,125 20650  [    http-8080-2] WARN  .struts2.dispatcher.Dispatcher  - Could not find action or result: /ilcps_web/sysadmin/deptAction_listNo result defined for action cn.mmd.login.action.DeptAction and result successat com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:273)at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)at 

 

1.1.2 异常场景

1.1.3 异常分析过程

Could not find action or result: /ilcps_web/sysadmin/deptAction_listNo result defined for action cn.mmd.login.action.DeptAction and result success

这句话就说明了原因,就是没有找到action 或者result.

1.1.4 异常解决方案

检查JSP和ACTION类的action或result,是否相对应,或者action的result写重复了导致了这个错误

1.1.5 资源

 

1.2 easyUI的 datagride显示异常(ID显示异常)

1.2.1 异常信息

转存失败,建议直接上传图片文件 

image.png EasyUIDatagride选择不了而且ID显示异常

1.2.2 异常场景****

把部门信息显示出来的时候

1.2.3 异常分析过程****

在数据库中的ID和页面显示的ID 不一致,先排除是数据库的问题,

然后再看看是不是后台输出有问题

直接打印出从数据库获得的数据是否正确

转存失败,建议直接上传图片文件 

image.png 后台输出数据正确,说明是前台问题

 

最后找了助教,用了大概20分钟的时间找出了BUG

是浏览器问题,我用的是谷歌浏览器  版本 63.0.3236.0(正式版本) (64 位)

1.2.4 异常解决方案

换个浏览器就行了

1.2.5 资源

 

1.3 ERROR .DefaultDispatcherErrorHandler  - Exception occurred during processing request: null

1.3.1 异常信息

2017-11-14 21:28:21,808 46268  [    http-8080-1] ERROR .DefaultDispatcherErrorHandler  - Exception occurred during processing request: nulljava.lang.NullPointerExceptionat cn.mmd.base.Service.impl.BaseServiceImpl.findAll(BaseServiceImpl.java:38)at cn.mmd.base.Service.impl.BaseServiceImpl$$FastClassBySpringCGLIB$$43fd96bf.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:651)at cn.mmd.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$e07fac78.findAll(<generated>)at cn.mmd.login.action.UserAction.listResult(UserAction.java:61)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:601)at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)

 

1.3.2 异常场景

查询用户列表的时候出的错

1.3.3 异常分析过程

这个错误不会走后台。是页面表单的属性与后台属性的不一致导致的。好好检查你的页面属性和字段属性配置。也可能是有的属性你没写。 下面报错说了你的xwork2 也就是struts2的ognl或者el表达式的对象里与request里面的属性不一致。

 

转存失败,建议直接上传图片文件 

image.png 在进入里面打个断点发现userService里的BaseDao为空!

image.png

image.png

1.3.4 异常解决方案

1.3.5 资源

 

1.4 从数据库拿出来的数据在 JA VA显示的跟数据库不一样

1.4.1 异常信息

转存失败,建议直接上传图片文件 

1.4.2 异常场景

获取ORACLE数据库的数据

1.4.3 异常分析过程

1.4.4 异常解决方案

数据库写的SQL语句执行之后没有提交,导致数据库和获取到的值不一样!

提交事务即可

转存失败,建议直接上传图片文件 

1.4.5 资源

1.5 exception 2 – test

1.5.1 异常信息

2017-11-22 13:39:31,424 169638 \[    http-8080-1] ERROR .DefaultDispatcherErrorHandler  - Exception occurred during processing request: The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null!org.springframework.dao.InvalidDataAccessApiUsageException: The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null!at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384)。。。。。t cn.mmd.base.Service.impl.BaseServiceImpl.findOne(BaseServiceImpl.java:23)at cn.mmd.base.Service.impl.BaseServiceImpl$FastClassBySpringCGLIB$43fd96bf.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)。。。Caused by: java.lang.IllegalArgumentException: The given id must not be null!at org.springframework.util.Assert.notNull(Assert.java:115)at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findOne(SimpleJpaRepository.java:223)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

 

1.5.2 异常场景

修改货物附件的时候出现了这个BUG

1.5.3 异常分析过程

根据BUG 的字面意思是没有找到ID而且看出来是跟后台找不到ID有关

观察JSP页面的ID字段和后台模型驱动是否一致即可

1.5.4 异常解决方案

1.5.5 资源

 

1.6  命令行解析WSDL时出现无法读取WSDL文档错误

1.6.1 异常信息

H:\Mytest\test4WebService>wsimport -s . http://localhost:3434/hello?wsdl正在解析 WSDL...  [ERROR] Connection refused: connect 无法读取 WSDL 文档: http://localhost:3434/hello?wsdl, 原因为 1) 找不到文档; 2) 无法读取文档; 3) 文档的根元素不是 wsdl:definitions。  [ERROR] failed.noservice=在提供的 WSDL 中找不到 wsdl:service: 需要至少提供一个 WSDL, 该 WSDL 至少具有一个服务定义。          无法解析 WSDL。

 

1.6.2 异常场景

image.png

1.6.3 异常分析过程

这个错误说明WSDL有错误,WSDL有错误说明在发布项目时就已经写错 了代码了,仔细观察代码在service接口中漏写了一个注解@WebServie

@WebServicepublic interface HelloService { public String sayHI(String name);}

写上了就成功了

1.6.4 异常解决方案

1.6.5 资源

 

1.7 Spring 整合Redis 启动 项目报错

1.7.1 异常 信息

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'smsListener': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisTemplate' defined in file [E:\eclipse_zuoye\ilcps_jms\target\classes\applicationContext-redis.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: RedisConnectionFactory is required

1.7.2 异常 场景****

启动web项目的时候加载applicationContext.xml报错

1.7.3 异常分析 过程****

creating bean with name 'redisTemplate' defined in file [E:\eclipse_zuoye\ilcps_jms\target\classes\applicationContext-redis.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: RedisConnectionFactory is required

异常信息已经说的很清楚,就是创建RedisTemplate的时候没有RedisConnectionFactory

1.7.4 异常 解决方案

image.png

1.7.5 资源

image.png

 

1.8 dao使用 JPQL语句 更新数据

1.8.1 异常信息

org.springframework.dao.InvalidDataAccessApiUsageException:org.hibernate.hql.internal.QueryExecutionRequestException:Not supported for DML operations [update com.kongkong.domain.Dept set deptName = ?2 where deptId = ?1];nested exception is java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException:Not supported for DML operations [update com.kongkong.domain.Dept set deptName = ?2 where deptId = ?1]Caused by: java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException:Not supported for DML operations [update com.kongkong.domain.Dept set deptName = ?2 where deptId = ?1]Caused by: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [update com.kongkong.domain.Dept set deptName = ?2 where deptId = ?1]

1.8.2 异常 场景

Dao使用JPQL语句

1.8.3 异常 分析过程

Caused by: java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException:

Not supported for DML operations [update com.kongkong.domain.Dept set deptName = ?2 where deptId = ?1]

不支持DML操作

1.8.4 异常 解决方案

image.png

1.9 Error Creating bean with name

image.png

1.9.1 原因:

注入service的时候写成这样private ServiceImpl  service;

1.9.2 应该是:

 private Iservice service;注入的时候写的应该是接口

 

 

1.10 can not set int field to null

1.10.1 截图

image.png

 

1.10.2 原因

实体类的state是int类型,表中有null存在,不能把null赋值给int

 

1.10.3 解决

把state的数据类型改成Integer就可以

 

1.11 failed to load ApplicationContext

 

1.11.1 截图

image.png

image.png

1.11.2 原因

导致加载配置文件失败的原因有很多,碰到一个比较特殊的:Jap的条件查询,findBy+属性;这里的属性是实体类的属性,不是表字段,如果写了字段名字,就会出现failed to load ApplicationContext的异常

1.11.3 解决

写成属性名字就可以

1.12 404错误

 

1.12.1 截图

image.png

1.12.2 原因

这里的location=“”前面一定有“/” 否则会包404错误!!

1.13 部门修改时异常 .

1.13.1 异常信息

org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.amaz.entity.Dept with id ; nested exception is javax.persistence.EntityNotFoundException: Unable to find com.amaz.entity.Dept with id 

image.png

1.13.2 异常场景

(1)  异常场景描述

在修改模块是:如果改行的数据上级部门为空,则修改提交时会包异常

 

(2)  异常场景代码 (导致错误的代码)

image.png

image.png  

 

 

1.13.3 异常分析过程

1),由于在利用save(进行)修改时,会先到数据库中查询出相应的数据,由于父部门id为””,导致查询的时候报错

1.13.4 异常解决方案

在service里面进行判断 如果是””则将值赋值为null 如下:

@Override

public void saveOrUpdateDept(Dept dept) {

if(dept.getDeptP()!=null&&"".equals(dept.getDeptP().getDeptId())){

dept.setDeptP(null);

}

deptDao.save(dept);

}

 

1.14 Shiro框架权限注解标在Action上面的异常处理

1.14.1 异常信息

1,空指针异常,

1.14.2 异常分析

由于service无法通过接口名进行自动注入,如下面代码 :

此时的deptService是无法注入的 导致之后所有的动作方法中 deptService为空

image.png

1.14.3 异常解决方案****

1,利用set方法注入,

image.png

2,通过使用名称注入

image.png

 

1.14.4 资源

这样配置能完美解决action上进行权限控制,完美的控制每一次请求的权限控制

1.15 EsayUI所属部门与上级领导的联动异常

1.15.1 异常信息

通过formatt格式化combox之后的数据能显示,但无法被选中,或无法显示领导真是姓名;

1.15.2 异常分析

由于formatt格式或之后的数据只是作为显示页面而用,在进行combox进行选中的时候,所选择的是选中的valuefiled这个值,由于

1.15.3 异常解决方案

image.png

image.png

image.png 如果valuefiled使用userinfo.name ,此时jsp页面是无法解析,所有无法被选中

1.16  添加用户异常

org.springframework.orm.jpa.JpaObjectRetrievalFailureException:Unable to findcom.itheima.domain.Userwith id ee6cf6c6-6c0f-486f-83b6-2091598a3708

1.16.1 解决方案:用户表及其用户明细、经理表和经理明细,由于设置了手动添加id,必须为他们赋予id

1.17 加载配置文件异常

1.17.1 异常信息

1. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jmsQueueTemplate' defined in file [D:\java\MyAndriod\workspace\ilcps_client\ilcps_client_web\target\classes\spring\applicationContext-mq-send.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.jms.ConnectionFactory]: Could not convert constructor argument value of type [org.springframework.data.redis.connection.jedis.JedisConnectionFactory] to required type [javax.jms.ConnectionFactory]: Failed to convert value of type [org.springframework.data.redis.connection.jedis.JedisConnectionFactory] to required type [javax.jms.ConnectionFactory]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.data.redis.connection.jedis.JedisConnectionFactory] to required type [javax.jms.ConnectionFactory]: no matching editors or conversion strategy found

1.17.2 异常解决方案

 2. 解决 ActiveMQ配置文件的connectionFactory和redis配置文件的connectionFactory的重名,造成容器创建实体异常

1.18 加载配置文件异常

1.18.1 异常信息

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userClientServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.itheima.dao.UserClientDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

1.18.2 异常解决方案

解决方案: 配置文件的扫描包名错误,修改即可

1.19 Unable to instantiate Action, xxxAction, defined for 'xxx' in namespace '/'xxxAction解决方案

 

出现这个问题的原因主要有两个

1、如果项目没有使用Spring,则struts.xml配置文件中,这个action的class属性的路径没有写完整,应该是包名.类名

2、如果项目使用了Spring,那就是applicationContext.xml里面没有为这个action定义bean。这样strus.xml中的对应action的class属性的值就是Spring配置文件中bean的id,比如:

<bean id="adminAction" class="go.derek.action.AdminAction"  

    scope="prototype">  

  

struts.xml

<action name="admin" class="adminAction" method="execute">  

          /admin.jsp  

  

 

 

 

 

 

 

1.20  .heibernate

org.hibernate.hql.ast.QuerySyntaxException: xxx is not mapped [from xxx] 或者

nested exception is org.hibernate.hql.internal.ast. QuerySyntaxException

1.20.1 详细异常信息


转存失败,建议直接上传图片文件 

21:08:31,951 ERROR DefaultDispatcherErrorHandler:42 - Exception occurred during processing request: Customer is not mapped [from Customer]; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: Customer is not mapped [from Customer]

org.springframework.orm.hibernate5.HibernateQueryException: Customer is not mapped [from Customer]; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: Customer is not mapped [from Customer]

    at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:176)

    at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:344)

    at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:309)

 

1.20.2 问题分析与解决:

上面的异常的抛出主要有几个方面:

1、如果你使用的xml配置文件开发方式,检查hibernate核心配置文件中是否声明映入实体类的映射文件。简单是说,使用标建立实体类与表的映射关系。

2、检查HQL语句书写书否正确。From 后面跟的是实体类名称而不是数据表的名称,同时注意大小写和单词拼写错误,以及不能包含中多的空格。

3、如果经过以上两步的检测,执行结果仍然报上面的错误信息,那么在你hql语句中from 后面直接跟实体类的全名称。

 

 

 

 

 

 

1.21 jms

javax.jms.JMSException: Unknown data type: 47

 

1.21.1 解决方法:

默认连接端口为61616

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://172.168.10.153:61616");****