kjbproperty 로딩 순서 및 NPE 문제 수정
This commit is contained in:
+6
-5
@@ -41,12 +41,13 @@ public class MonitoringPropertyService
|
||||
id.setPrptyName(prptyName);
|
||||
|
||||
Optional<MonitoringProperty> property = repository.findById(id);
|
||||
if (property.isPresent() && !property.get().getPrpty2Val().isEmpty()) {
|
||||
return property.get().getPrpty2Val();
|
||||
} else {
|
||||
return defaultValue;
|
||||
if (property.isPresent()) {
|
||||
String value = property.get().getPrpty2Val();
|
||||
if (value != null && !value.isEmpty()) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Iterable<MonitoringProperty> findAllByIdPrptyName(String prptyName) {
|
||||
|
||||
@@ -17,13 +17,14 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -55,11 +56,7 @@ public class UmsDispatchService {
|
||||
MessageRequestRepository messageRequestRepository
|
||||
) {
|
||||
this.kjbPropertyInjector = new KjbPropertyInjector(monitoringPropertyService, PROP_GORUP_ID);
|
||||
|
||||
this.messageRequestRepository = messageRequestRepository;
|
||||
// this.kjbEmailService = kjbEmailService;
|
||||
// this.kjbSafedbWrapper = kjbSafedbWrapper;
|
||||
// this.monitoringPropertyService = monitoringPropertyService;
|
||||
|
||||
this.executorService = new ThreadPoolExecutor(
|
||||
CORE_POOL_SIZE,
|
||||
@@ -72,21 +69,16 @@ public class UmsDispatchService {
|
||||
this.transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
log.debug("UmsDispatchService initialized with thread pool - core: {}, max: {}, queue: {}",
|
||||
CORE_POOL_SIZE, MAX_POOL_SIZE, QUEUE_CAPACITY);
|
||||
}
|
||||
|
||||
|
||||
KjbProperty prop = new KjbProperty();
|
||||
// prop.setEaiBatchUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.url"));
|
||||
// prop.setUmsEaiBatchSendDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.send_dir"));
|
||||
// prop.setUmsEaiBatchBackupDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.backup_dir"));
|
||||
// prop.setUmsEaiBatchInterfaceId(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.interface_id"));
|
||||
// prop.setUmsHostUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.host_url"));
|
||||
// prop.setUmsApiKey(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.api_key"));
|
||||
prop = kjbPropertyInjector.inject(prop);
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
KjbProperty prop = kjbPropertyInjector.inject(new KjbProperty());
|
||||
|
||||
try {
|
||||
this.kjbUmsService = new KjbUmsService(prop);
|
||||
|
||||
this.kjbEmailSendModule = KjbEmailSendModule.getInstance(prop, messageRequestRepository);
|
||||
log.info("KjbUmsService and KjbEmailSendModule initialized successfully");
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to initialize KjbUmsService or KjbEmailSendModule: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -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