Java - Orika 1.4.5 - OutOfMemoryException:PermGen Space

Java - Orika 1.4.5 - OutOfMemoryException : PermGen Space

我在使用 Orika 1.4.5 和 PermGen 时遇到问题 Space。

确实,我是这样使用 ConfigurableMapper 的:

 public class SoapSearchPrdvFreeSlotsMapper extends ConfigurableMapper {
@Override
public void configure(MapperFactory mapperFactory) {
    mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2Filter.class)
                .field("typeRdv", "wsldtTypeRdv")
                .field("motifId", "wsldtMotifId")
                .byDefault().toClassMap());
    }
    mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2.class)
                .field("typeRdv", "wsldtTypeRdv")
                .field("motifId", "wsldtMotifId")
                .field("quantum", "wsldtActiviteIdActivQuantum")
                .field("activiteJours", "wsldtActiviteIdActivJours")
                .field("activiteHeureFerme", "wsldtActiviteIdActivHeureFerme")
                .field("activiteHeureOuvert", "wsldtActiviteIdActivHeureOuvert")
                .field("startDate", "disDate")
                .field("disCapacity", "disCapacite")
                .field("disReserve", "disReserve")
                .field("reserveCC", "wsldtReserveCC")
                .byDefault().toClassMap());
    }
}

@Override
public void configureFactoryBuilder(DefaultMapperFactory.Builder builder) {
    builder.build().getConverterFactory().registerConverter(new DateXmlDateConverter());
}

}

但是每次我调用这个映射器时,我都会自动生成 class 个存储在 PermGen 中的映射器。

我尝试使用 MapperFactory 的 "existsRegisteredMapper" 来防止 class 映射器自动生成,但它不起作用:

public static <T, U> boolean existsRegisteredMapperInFactory(MapperFactory mapperFactory, Class<T> classSrc, Class<U> classDest) {
    return mapperFactory.existsRegisteredMapper(TypeFactory.valueOf(classSrc), TypeFactory.valueOf(classDest), true);
}

和修改后的第一个代码块:

if (!existsRegisteredMapperInFactory(mapperFactory, PrdvWsListerDispoTelV2Filter.class, PrdvFreeSlot.class)) {
        mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2Filter.class)
                .field("typeRdv", "wsldtTypeRdv")
                .field("motifId", "wsldtMotifId")
                .byDefault().toClassMap());
    }

拜托,有没有办法在不重写我拥有的所有映射器的情况下防止 class 映射器自动生成?

感谢您的帮助。

请确保映射器是单例。你不需要每次都实例化它。

您无需验证映射器是否已注册。它只会生成一次(每个 MapperFactory 实例)。

所以只要确保 SoapSearchPrdvFreeSlotsMapper 是一个单例(只有一个实例,ConfigurableMapper 是线程安全的)