hibernate与struts2一起时的异常处理

来源:互联网 发布:java培训有哪些骗局 编辑:程序博客网 时间:2024/06/04 19:38

今天项目刚将hibernate与struts2放一起。异常还不少。

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...log4j:WARN No appenders could be found for logger (freemarker.cache).

解决:Log4j2以上版本需要放在log4j-的jar包和log4j-core核心包。

java.lang.NoSuchMethodError: org.apache.logging.log4j.status.StatusLogger.debug(Ljava/lang/String;Ljava/lang/Object;)

commons-logger.jar和你的log4j.jar版本不兼容。前者是对后者的一个封装,而hibernate中主要是使用前者。前者的功能就是:它封装了一些通常的日志类,比如log4j,java.util.logging.Logger 等,使用的log4j,但是由于版本不对,commons-logger中用了log4j中的那个类,在当前的log4j版本中已经不存在了,所以报错

/hibernate.cfg.xml not found

解决:如果之前的hibernate都能正常运行,那么出现这种情况时,将hibernate放在src下面即可。

 An AnnotationConfiguration instance is required to use <mapping class="entity.District"/>

解决:很明显。用了注解。4.0版本之前记得在配置前用:

new AnnotationConfiguration().configure();

4.0之后的hibernate改用注册的方法了,不存在这个问题了。

0 0
原创粉丝点击