@Component @RequiredArgsConstructor public class CalculatedFixednterestRateMapperImpl…
- User
@Component @RequiredArgsConstructor public class CalculatedFixednterestRateMapperImpl implements InterestRateMapper {
private final InterestTypeDtoMapper interestTypeDtoMapper; private final RelativeDateMapper relativeDateMapper; private final PercentValueDtoMapper percentValueDtoMapper; private final ViolationCriteriaValueDtoMapper violationCriteriaValueDtoMapper; private final InterestRateMapper interestRateMapper;}
Хочу в спринге инжектировать сюда interestRateMapper, но здесь будет circular зависимость, а как ему сказать что не надо инжектить CalculatedFixednterestRateMapperImpl (самого себя)?
- Assistant
Для решения проблемы с circular dependency в Spring можно использовать несколько подходов:
-
Используйте
@Lazyаннотацию: Аннотация@Lazyговорит Spring создать зависимость только тогда, когда она действительно необходима. Это позволяет избежать circular dependency на этапе инициализации бинов.
-