kjbproperty 로딩 순서 및 NPE 문제 수정
This commit is contained in:
@@ -30,6 +30,11 @@ public class KjbPropertyInjector {
|
||||
String rawValue = monitoringPropertyService.getPropertyValue(groupId, key, anno.defaultValue());
|
||||
Object convertedValue = convertValue(field.getType(), rawValue);
|
||||
|
||||
// null이면 필드의 기본값 유지 (primitive 타입에 null 할당 방지)
|
||||
if (convertedValue == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
field.set(property, convertedValue);
|
||||
@@ -46,16 +51,26 @@ public class KjbPropertyInjector {
|
||||
|
||||
private static Object convertValue(Class<?> type, String rawValue) {
|
||||
if (rawValue == null) return null;
|
||||
if (StringUtils.isEmpty(rawValue)) return "";
|
||||
|
||||
if (type == String.class) return rawValue;
|
||||
if (type == Integer.class || type == int.class) return Integer.valueOf(rawValue);
|
||||
if (type == Long.class || type == long.class) return Long.valueOf(rawValue);
|
||||
if (type == Double.class || type == double.class) return Double.valueOf(rawValue);
|
||||
if (type == Boolean.class || type == boolean.class) return Boolean.valueOf(rawValue);
|
||||
if (type == Float.class || type == float.class) return Float.valueOf(rawValue);
|
||||
if (type == Short.class || type == short.class) return Short.valueOf(rawValue);
|
||||
if (type == Byte.class || type == byte.class) return Byte.valueOf(rawValue);
|
||||
|
||||
// 빈 문자열인 경우 primitive 타입은 null 반환 (필드의 기본값 유지)
|
||||
if (StringUtils.isEmpty(rawValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (type == Integer.class || type == int.class) return Integer.valueOf(rawValue);
|
||||
if (type == Long.class || type == long.class) return Long.valueOf(rawValue);
|
||||
if (type == Double.class || type == double.class) return Double.valueOf(rawValue);
|
||||
if (type == Boolean.class || type == boolean.class) return Boolean.valueOf(rawValue);
|
||||
if (type == Float.class || type == float.class) return Float.valueOf(rawValue);
|
||||
if (type == Short.class || type == short.class) return Short.valueOf(rawValue);
|
||||
if (type == Byte.class || type == byte.class) return Byte.valueOf(rawValue);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Failed to convert value '{}' to type {}, returning null", rawValue, type.getSimpleName());
|
||||
return null;
|
||||
}
|
||||
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user