🐛 防止循环依赖引用错误

使用 ApplicationContext 获取 Bean 来进行注入
This commit is contained in:
徐晓伟
2023-03-30 10:56:40 +08:00
parent 1983d002b4
commit b7fe6fb1d2
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.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -118,9 +119,13 @@ public class OrderServiceImpl implements OrderService {
@Autowired
private StoreSeckillService storeSeckillService;
@Autowired
private StoreCombinationService storeCombinationService;
@Autowired
public void setStoreCombinationService(ApplicationContext applicationContext) {
this.storeCombinationService = applicationContext.getBean(StoreCombinationService.class);
}
@Autowired
private StoreBargainService storeBargainService;

View File

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