spring/hibernate/struts2常见异常总结

  • Spring

①ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException java

缺乏aspectjweaver.jar,该jar包经常使用于spring aop中 web

 

②java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL  spring

http://blessht.iteye.com/blog/1104450 app

 

③java.lang.NoSuchMethodException: $Proxy7.方法名() less

spring aop中常见,aop的实现是代理,java领域代理有两种:jdk自带的针对接口的代码和cglib针对类的代码。spring aop默认使用jdk接口代理,某些时候访问的bean没有接口故出现以上问题,解决方法:在aop配置中修改代理类型: ssh

 

Xml代码   收藏代码
  1. <aop:config proxy-target-class="true">  

 

④ClassNotFoundException javax/mail/MessagingException spa

spring配置javamailsenderimpl时出错,缘由是缺乏mail.jar这个包,将该jar包放入项目lib中便可 hibernate

 

  • Hibernate

①Unable to locate appropriate constructor on class 代理

指定类找不到对应的构造方法,常出现于hql,确认hql中每一个类型与Hibernate构造方法对应,而且构造方法的每一个参数类型与hbm.xml文件对应 xml

 

②org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ON near line 1

异常发生在HQL上面:select a.name,b.age from TableA a left join TableB b ONa.id=b.id。原来Hibernate不支持ON这种表达式,若是要创建两表关系就将ON替代为WHERE便可:

select a.name,b.age from TableA a left join TableB b where a.id=b.id

 

③java.lang.NullPointerException at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:125)

异常发生在HQL上:select a.name,sum(b.age) from TableA a left join TableB b where a.id=b.id,异常发生缘由跟下面第④个是同样的。

④org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! 

异常发生在HQL上:select a.name,count(b.age) from TableA a left join TableB b where a.id=b.id。③和④的异常是同一缘由:就是left join!原来在Hibernate若是两张表没有设置one-to-many这样的映射关系的话,就不能使用join。第③个是由于sum和join同时出现形成的错误,第④个是由于有left join形成的。修改方法是将left join用逗号","取代:select a.name,sum(b.age) from TableA a,TableB b where a.id=b.id

相关文章
相关标签/搜索