I'm trying to fix a circular dependency in a legacy project.
@Service
@Slf4j
public class FlowpathSubscriber {
@Autowired
@Qualifier("pubSubTemplate")
private PubSubTemplate pubSubTemplate;
@Autowired
private FlowpathBigQueryProcessor flowpathBigQueryProcessor;
@Value("${subscription}")
private String subscription;
@Autowired
private ObjectMapper objectMapper;
@Autowired
@Lazy
private SlackNotificationService slackNotificationService;
I added @Lazy
to SlackNotificationService
as it was causing a circular dependency issue. However adding @Lazy
causes an error during Gradle compilation:
error: cannot find symbol @Lazy
CodePudding user response:
Add:
import org.springframework.context.annotation.Lazy;
CodePudding user response:
Do 2 things:
- don't forget to import
Lazy
i.e.import org.springframework.context.annotation.Lazy
; - You need to put
@Lazy
onSlackNotificationService
bean(component) as well.
See this: https://www.baeldung.com/spring-lazy-annotation#2-with-autowired