java.lang.NoClassDefFoundError异常

来源:互联网 发布:2016八月经济数据 编辑:程序博客网 时间:2024/05/07 02:46

昨晚在部署时出的问题,总结下。

java.lang.NoClassDefFoundError异常?

错误信息:

java.lang.NoClassDefFoundError:Could not initialize class com.xxx.RedisUtils

java.lang.NoClassDefFoundError:

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

简单理解就是类加载器试图加载类的定义,但是找不到这个类的定义,而实际上这个类文件是存在的(说就是在加载这个类文件时出错)。
与之类似的是:

java.lang.ClassNotFoundException:

Thrown when an application tries to load in a class through its string name using:1. The forName method in class Class.2. The findSystemClass method in class ClassLoader .3. The loadClass method in class ClassLoader.but no definition for the class with the specified name could be found.

因为类文件没有找到报错。

分析:

1.首先存在RedisUtils.class文件;
2.怀疑在初始化class文件时出错,那么就需要考虑static修饰的变量,这些变量都是在加载类时实例化的;

    private static final String PREFIX = "";    private static final String SINGLETONFLAG = "";    private static final String VALUES = "";    private static final int TIME = Integer.parseInt(ConfigUtil.getConfigByName(""));    //标示    private static final ThreadLocal<Boolean> FLAG = new ThreadLocal<Boolean>() {        @Override        protected Boolean initialValue() {            return Boolean.TRUE;        }    };

其中嫌疑最大的是Integer.parseInt(ConfigUtil.getConfigByName(“”));因为参数如果为空会发生异常,那么这个类的实例化就会失败;这个参数是从配置文件中取出的检测正式服务器上配置文件果然这个配置不见了。
3.更改配置文件后问题得到解决。

0 0