I am getting java.lang.OutOfMemoryError: Metaspace error after running my Spring boot program for few days. Memory profiling showed the issue is in Orika library. This is how I used Orika in my app. I guess I have used orika in wrong manner.
In controller
ChangePropertyRequest changePropertyRequest
= OrikaMapperFactory.getMapperFactory(OrikaMapperFactory.OrikaMapper.CHANGE_PROPERTY_REQUEST_FACTORY)
.map(changePropRequestMsg.getChangePropRequestMsg().getValue().getChangePropertyRequest().getValue(), ChangePropertyRequest.class);
In OrikaMapperFactory
public interface OrikaMapperFactory {
static MapperFacade getMapperFactory(@NotNull OrikaMapper orikaMapper) {
switch (orikaMapper) {
case CHANGE_PROPERTY_REQUEST_FACTORY:
return changePropertyRequestMapperFactory();
default:
return defaultMapperFacade();
}
}
enum OrikaMapper {
CHANGE_PROPERTY_REQUEST_FACTORY
}
}
In OrikaMapperFactoryImpl
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class OrikaMapperFactoryImpl implements OrikaMapperFactory {
private static final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
public static MapperFacade defaultMapperFacade() {
return mapperFactory.getMapperFacade();
}
static {
final ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("resultHeaderConverter", new ResultHeaderToResultHeaderXsd());
}
public static MapperFacade changePropertyRequestMapperFactory() {
mapperFactory.classMap(ChangePropertyRequest.class, com.dto.ChangePropertyRequest.class)
.field("userId.value", "userId")
.field("commonProperty.value.accountCode.value", "commonProperty.accountCode")
.byDefault()
.register();
return mapperFactory.getMapperFacade();
}