bug罗 2023-05-11 14:15 采纳率: 0%
浏览 37

Handler dispatch failed; nested exception is java.lang.NoClassDefFoundErro

本地自己写了一个工具类,打包的时候也正常,也有打包到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 "";
        }
    }

}
  • 写回答

1条回答 默认 最新

  • Soulic 2023-05-11 18:09
    关注

    使用什么服务器软件呢?
    检查运行中的war包是不是已经有对应的类

    评论

报告相同问题?

问题事件

  • 创建了问题 5月11日

悬赏问题

  • ¥15 rt-thread线程切换的问题
  • ¥20 python忆阻器数字识别
  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊