🐛 防止循环依赖引用错误

使用 ApplicationContext 获取 Bean 来进行注入
This commit is contained in:
徐晓伟
2023-03-30 10:56:40 +08:00
parent 8c2a9dce29
commit f9a37a2d38
2 changed files with 12 additions and 2 deletions

View File

@@ -46,6 +46,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -118,9 +119,13 @@ public class OrderServiceImpl implements OrderService {
@Autowired @Autowired
private StoreSeckillService storeSeckillService; private StoreSeckillService storeSeckillService;
@Autowired
private StoreCombinationService storeCombinationService; private StoreCombinationService storeCombinationService;
@Autowired
public void setStoreCombinationService(ApplicationContext applicationContext) {
this.storeCombinationService = applicationContext.getBean(StoreCombinationService.class);
}
@Autowired @Autowired
private StoreBargainService storeBargainService; private StoreBargainService storeBargainService;

View File

@@ -35,6 +35,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
@@ -90,9 +91,13 @@ public class StoreCombinationServiceImpl extends ServiceImpl<StoreCombinationDao
@Autowired @Autowired
private StoreOrderService storeOrderService; private StoreOrderService storeOrderService;
@Autowired
private OrderService orderService; private OrderService orderService;
@Autowired
public void setOrderService(ApplicationContext applicationContext) {
this.orderService = applicationContext.getBean(OrderService.class);
}
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;