`
rich8w
  • 浏览: 180660 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Exception in thread "pool-2-thread-1" java.lang.NoClassDefFoundError:

    博客分类:
  • Java
阅读更多
其实这个错误情况根本无法给我准确的定位到错误代码。

单例的代码
public class DAOFactory {
		
	//....省略
	
	private static class SingletonHolder {
		//只有在调用的时候才会初始化!而且线程安全。
        static DAOFactory instance = new DAOFactory();
    }  
	
	public static DAOFactory getInstance() {
		return SingletonHolder.instance;
	}
}


期间我加了个ControlDao的一些ibatis的class和module竟然报错误:
Exception in thread "pool-2-thread-1" java.lang.NoClassDefFoundError: Could not initialize class com.xxxx.dao.DAOFactory$SingletonHolder



找啊找,最后我试着改成,不用单例:
public class DAOFactory {
		
	//....省略
	
	public static DAOFactory getInstance() {
		return new DAOFactory():
	}
}


结果就出现了正确的ibatis错误定位了:
java.lang.RuntimeException: Error occurred.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/insert'.  Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'test' in class 'com.xxx.module.Control'

终于找到原因了,竟然是我的sql语句没写好,改好,再改回原来的单例,运行正常了。
0
1
分享到:
评论
1 楼 rich8w 2010-01-05  
由于把单例的DAOFactory注释掉了
/*错误代码*/
public static DAOFactory getInstance() {
		return new DAOFactory();
		//return SingletonHolder.instance;
	}




产生了意想不到的异常了,我明明已经startTransaction了,可还提示我没started。

com.ibatis.common.jdbc.exception.NestedSQLException: Could not commit transaction.  Cause: com.ibatis.sqlmap.engine.transaction.TransactionException: TransactionManager could not commit.  No transaction is started.
	at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.commitTransaction(SqlMapExecutorDelegate.java:719)
	at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.commitTransaction(SqlMapSessionImpl.java:172)
	at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.commitTransaction(SqlMapClientImpl.java:148)



改回单例就一切OK了。

相关推荐

Global site tag (gtag.js) - Google Analytics