Eureka unit test error creating bean with name ‘Eureka autoservice registration’: Singleton bean

 If you encounter the following error message during unit testing, there are two ways to resolve it
 org.springframework.beans.factory.BeanCreationNotAllowedException:
 Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean...

Method 1: add notes

Add the following annotation to the unit test class (rest assured that there will be no local reference, but it cannot be deleted)

@MockBean
private EurekaAutoServiceRegistration eurekaAutoServiceRegistration;

Method 2: implement the beanfactory postprocessor interface

@Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
        bd.setDependsOn("eurekaServiceRegistry", "inetUtils");
    }
}

Read More: