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

其实这个错误情况根本无法给我准确的定位到错误代码。

单例的代码
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语句没写好,改好,再改回原来的单例,运行正常了。

你可能感兴趣的:(java,DAO,thread,xml,ibatis)