本地自己写了一个工具类,打包的时候也正常,也有打包到war包里,但是在服务器里运行时就报:Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.yonyou.cpu.projectdef.util.JsonUtil
想知道这样问题是什么原因,应该怎么解决呢?
以下是JsonUtil类的全部内容
package com.yonyou.cpu.projectdef.util;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.IOException;
import java.text.SimpleDateFormat;
public final class JsonUtil {
private static ObjectMapper MAPPER = generateMapper(Inclusion.ALWAYS);
public static Object fromJson(String json, Class clazz) throws IOException {
return clazz.equals(String.class)?json:MAPPER.readValue(json, clazz);
}
public static Object fromJson(String json, TypeReference typeReference) throws IOException {
return typeReference.getType().equals(String.class)?json:MAPPER.readValue(json, typeReference);
}
public static String toJson(Object src) throws IOException {
return src instanceof String?(String)src:MAPPER.writeValueAsString(src);
}
public static String toJson(Object src, Inclusion inclusion) throws IOException {
if(src instanceof String) {
return (String)src;
} else {
ObjectMapper customMapper = generateMapper(inclusion);
return customMapper.writeValueAsString(src);
}
}
public static String toJson(Object src, ObjectMapper mapper) throws IOException {
return null != mapper?(src instanceof String?(String)src:mapper.writeValueAsString(src)):null;
}
public static ObjectMapper mapper() {
return MAPPER;
}
private static ObjectMapper generateMapper(Inclusion inclusion) {
ObjectMapper customMapper = new ObjectMapper();
customMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
customMapper.configure(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, true);
customMapper.configure(Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
customMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
Version ver = new Version(0, 0, 0, "SNP");
SimpleModule module = new SimpleModule("StringModule", ver);
module.addSerializer(String.class, new StringUnicodeSerializer());
module.addSerializer(Number.class, new NumberBigDecimalSerializer());
customMapper.registerModule(module);
return customMapper;
}
public static String quote(String string) {
if(string != null && string.length() != 0) {
int len = string.length();
StringBuffer sb = new StringBuffer(len + 4);
for(int i = 0; i < len; ++i) {
char c = string.charAt(i);
switch(c) {
case 8:
sb.append("\\b");
break;
case 9:
sb.append("\\t");
break;
case 10:
sb.append("\\n");
break;
case 12:
sb.append("\\f");
break;
case 13:
sb.append("\\r");
break;
case 34:
case 47:
case 92:
sb.append('\\');
sb.append(c);
break;
default:
if(c >= 32 && c < 128) {
sb.append(c);
} else {
String t = "000" + Integer.toHexString(c);
sb.append("\\u" + t.substring(t.length() - 4));
}
}
}
return sb.toString();
} else {
return "";
}
}
}
使用什么服务器软件呢?
检查运行中的war包是不是已经有对应的类
因为你T@M傻P