Browse Source

Merge pull request #10385 from YevhenBondarenko/fix/entity-service-registry

fixed NPE related to the entity service registry initialization
pull/10394/head
Viacheslav Klimov 3 years ago
committed by GitHub
parent
commit
e3a940c575
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      dao/src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java
  2. 14
      dao/src/main/java/org/thingsboard/server/dao/entity/DefaultEntityServiceRegistry.java

2
dao/src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java

@ -17,6 +17,7 @@ package org.thingsboard.server.dao.entity;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.thingsboard.server.common.data.HasCustomerId; import org.thingsboard.server.common.data.HasCustomerId;
@ -60,6 +61,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
private EntityQueryDao entityQueryDao; private EntityQueryDao entityQueryDao;
@Autowired @Autowired
@Lazy
EntityServiceRegistry entityServiceRegistry; EntityServiceRegistry entityServiceRegistry;
@Override @Override

14
dao/src/main/java/org/thingsboard/server/dao/entity/DefaultEntityServiceRegistry.java

@ -17,15 +17,12 @@ package org.thingsboard.server.dao.entity;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import javax.annotation.PostConstruct;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@Service @Service
@ -33,14 +30,13 @@ import java.util.Map;
@Slf4j @Slf4j
public class DefaultEntityServiceRegistry implements EntityServiceRegistry { public class DefaultEntityServiceRegistry implements EntityServiceRegistry {
private final ApplicationContext applicationContext; private final List<EntityDaoService> entityDaoServices;
private final Map<EntityType, EntityDaoService> entityDaoServicesMap = new HashMap<>(); private final Map<EntityType, EntityDaoService> entityDaoServicesMap = new HashMap<>();
@EventListener(ContextRefreshedEvent.class) @PostConstruct
@Order(Ordered.HIGHEST_PRECEDENCE)
public void init() { public void init() {
log.debug("Initializing EntityServiceRegistry on ContextRefreshedEvent"); log.debug("Initializing EntityServiceRegistry on ContextRefreshedEvent");
applicationContext.getBeansOfType(EntityDaoService.class).values().forEach(entityDaoService -> { entityDaoServices.forEach(entityDaoService -> {
EntityType entityType = entityDaoService.getEntityType(); EntityType entityType = entityDaoService.getEntityType();
entityDaoServicesMap.put(entityType, entityDaoService); entityDaoServicesMap.put(entityType, entityDaoService);
if (EntityType.RULE_CHAIN.equals(entityType)) { if (EntityType.RULE_CHAIN.equals(entityType)) {

Loading…
Cancel
Save