nadavgam
nadavgam

Reputation: 2412

unclear circular dependency with FeignClient and Spring boot

My springboot app was working fine untill I added the following class:

@Service
@RequiredArgsConstructor
public class AutoopsClientPostBootListener implements ApplicationListener<ContextRefreshedEvent>
{
    private final IAutoOpsGnsFlowInitiator gnsFlowInitator;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event)
    {
      gnsFlowInitator.startClient(event);
    }
}

For some odd reason after that, I get a circular dependency error stemming from feign client dependent on AutoopsClientPostBootListener from above.

It happens becasue IAutoOpsGnsFlowInitiator is dependent on the feign client which depend on AutoopsClientPostBootListener. But FeignClient doesn't even have any members.. (feign auto generates it) so how can it be dependent on the Listener?!!

whats the problem??

Thanks for the help

Upvotes: 2

Views: 1676

Answers (2)

elioth010
elioth010

Reputation: 46

The issue depends on the phase of your context, once your context is initialized or changes there is a call on refresh, so you event will be fired, if you need to execute your startClient once your context is fully initialized then you @EventListener will be trigger with ContextStartedEvent which is only called once your application context was fully initialized so feign is already loaded.

Hopefully this can be helpful.

Upvotes: 0

nadavgam
nadavgam

Reputation: 2412

So the problem was with ApplicationListener(no idea why). Using @EventListener solved the problem.

@EventListener
    public void onApplicationEvent(ContextRefreshedEvent event)
    {
      gnsFlowInitator.startClient(event);
    }

Upvotes: 3

Related Questions