You've already forked FrameTour-BE
refactor(core): 添加 Lazy 注解解决循环依赖问题
- 在多个 Service 类中为注入的依赖添加 @Lazy 注解 - 修改了微信支付服务实现类中的依赖注入方式 - 更新了打印机服务实现类中的依赖注入配置 - 调整了统计拦截器和服务类中的依赖注入策略 - 优化了 FaceService 和相关 Repository 的注入方式 - 防止应用启动时因循环依赖导致的初始化失败
This commit is contained in:
@@ -5,38 +5,23 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
|
||||
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* @author wenshijia
|
||||
* @date 2021年07月05日 18:34
|
||||
* 修改redis缓存序列化器
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class CustomRedisCacheManager {
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Bean
|
||||
public RedisCacheConfiguration redisCacheConfiguration() {
|
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(objectMapper, Object.class);
|
||||
|
||||
RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig();
|
||||
configuration = configuration.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)).entryTtl(Duration.ofMinutes(1));
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理redis连接工具显示redis key值显示乱码问题,value值没处理
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -50,18 +51,25 @@ import java.util.*;
|
||||
public class WxPayServiceImpl implements WxPayService {
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private PaymentMapper paymentMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private StatisticsMapper statisticsMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private OrderRepository orderRepository;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private OrderBiz orderBiz;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ScenicService scenicService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -119,29 +119,37 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
@Lazy
|
||||
private OrderBiz orderBiz;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private WxPayService wxPayService;
|
||||
@Autowired
|
||||
private PrintTaskMapper printTaskMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private IPriceCalculationService priceCalculationService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private IAutoCouponService autoCouponService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ScenicRepository scenicRepository;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private OrderRepository orderRepository;
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
@Autowired
|
||||
private FaceMapper faceMapper;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private FaceRepository faceRepository;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private FaceService faceService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private DeviceRepository deviceRepository;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private PrinterTaskPushService taskPushService;
|
||||
|
||||
// 用于优先打印的线程池,核心线程数根据实际情况调整
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ycwl.basic.stats.service.StatsService;
|
||||
import com.ycwl.basic.stats.util.StatsUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@@ -18,6 +19,7 @@ import java.util.HashSet;
|
||||
|
||||
@Component
|
||||
public class StatsInterceptor implements HandlerInterceptor {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private StatsService statsService;
|
||||
|
||||
|
||||
@@ -7,15 +7,18 @@ import com.ycwl.basic.stats.mapper.StatsMapper;
|
||||
import com.ycwl.basic.stats.mapper.StatsRecordMapper;
|
||||
import com.ycwl.basic.stats.service.StatsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class StatsServiceImpl implements StatsService {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private StatsMapper statsMapper;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private StatsRecordMapper statsRecordMapper;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user