Hey, how one should deal with static initializations in Spring ? I mean, my bean has a static initialization
private static final Map exce
Having static
dependencies on other beans is not a Spring way.
However, if you want to keep it static
, you can initialize it lazily - in that case depends-on
can enforce proper initialization order.
EDIT: By lazy loading I mean something like this (I use lazy initialization with holder class idiom here, other lazy initialization idioms can be used instead):
private static class ExceptionMappingHolder {
private static final Map exceptionMapping =
ErrorExceptionMapping.getExceptionMapping();
}
and use ExceptionMappingHolder.exceptionMapping
instead of exceptionMapping
.