spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

Can't start spring boot app with @EnableZuulProxy when consul server is down #1603

Closed proragab closed 7 years ago

proragab commented 7 years ago

I tried to register spring micro service on consul with spring retry option , in usual case the spring boot app retry to connect to consul by default 6 times , when i add @EnableZuulProxy the boot couldn't start and throws

==>org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat .. .. .. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.netflix.zuul.ZuulConfiguration$ZuulFilterConfiguration': Unsatisfied dependency expressed through field 'filters'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'preDecorationFilter' defined in class path resource [org/springframework/cloud/netflix/zuul/ZuulProxyConfiguration.class]: Unsatisfied dependency expressed through method 'preDecorationFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'routeLocator' defined in class path resource [org/springframework/cloud/netflix/zuul/ZuulProxyConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator]: Factory method 'routeLocator' threw exception; nested exception is com.ecwid.consul.transport.TransportException: java.net.ConnectException: Connection refused: connect

spencergibb commented 7 years ago

I think this belongs in Spring Cloud consul.

proragab commented 7 years ago

I posted it there , Thanks

ashokdudhade commented 7 years ago

@spencergibb I think this needs to be fixed in spring cloud netflix. DiscoveryClientRouteLocator constructor assumes that "getLocalServiceInstance" will return something or null. Instead it should see if discovery client provider is throwing any exception and if there is any exception then inject noop implementation. I would personally like to see fail-fast flag for discovery client.

public DiscoveryClientRouteLocator(String servletPath, DiscoveryClient discovery,
            ZuulProperties properties) {
        super(servletPath, properties);

        if (properties.isIgnoreLocalService()) {
            ServiceInstance instance = discovery.getLocalServiceInstance();
            if (instance != null) {
                String localServiceId = instance.getServiceId();
                if (!properties.getIgnoredServices().contains(localServiceId)) {
                    properties.getIgnoredServices().add(localServiceId);
                }
            }
        }
        this.serviceRouteMapper = new SimpleServiceRouteMapper();
        this.discovery = discovery;
        this.properties = properties;
    }