GithubHelp home page GithubHelp logo

Comments (12)

spencergibb avatar spencergibb commented on June 1, 2024 1

You'll need to describe your setup a bit more, because when I run, the node name is the hostname of the machine. If you can't resolve hostnames, maybe we should apply spring.cloud.consul.discovery.preferIpAddress here and choose.

from spring-cloud-consul.

spencergibb avatar spencergibb commented on June 1, 2024

@gitpg you can now use spring.cloud.consul.discovery.preferIpAddress=true.

from spring-cloud-consul.

gitpg avatar gitpg commented on June 1, 2024

Good solution, well done! Thanks

from spring-cloud-consul.

arun0009 avatar arun0009 commented on June 1, 2024

@spencergibb Is there a milestone repository that I can grab this fix from?

from spring-cloud-consul.

spencergibb avatar spencergibb commented on June 1, 2024

@arun0009 there has not been another milestone yet, but there is a snapshot in this repo:

<repository>
    <id>spring-snapshots</id>
    <name>Spring Snapshots</name>
    <url>http://repo.spring.io/libs-snapshot-local</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

at version 1.0.0.BUILD-SNAPSHOT.

from spring-cloud-consul.

arun0009 avatar arun0009 commented on June 1, 2024

Thanks @spencergibb

I tried to update to BUILD-SNAPSHOT but now I get this exception:

Exception in thread "main" java.lang.IllegalStateException: Error processing condition on org.springframework.cloud.consul.ConsulAutoConfiguration.consulProperties

even with

config:
        enabled: false

from spring-cloud-consul.

spencergibb avatar spencergibb commented on June 1, 2024

Can you give me more stack trace? The one line doesn't help.

from spring-cloud-consul.

arun0009 avatar arun0009 commented on June 1, 2024
 | java.lang.reflect.InvocationTargetException
 |  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 |  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 |  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 |  at java.lang.reflect.Method.invoke(Method.java:497)
 |  at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
 |  at java.lang.Thread.run(Thread.java:745)
 | Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.cloud.consul.ConsulAutoConfiguration.consulProperties
 |  at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:58)
 |  at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102)
 |  at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:190)
 |  at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148)
 |  at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124)
 |  at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318)
 |  at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239)
 |  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
 |  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
 |  at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
 |  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
 |  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
 |  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
 |  at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
 |  at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
 |  at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
 |  at com.api.notifications.service.NotificationsApiClient.main(NotificationsApiClient.java:61)
 |  ... 6 more
 | Caused by: java.lang.IllegalArgumentException: @ConditionalOnMissingBean annotations must specify at least one bean (type, name or annotation)
 |  at org.springframework.util.Assert.isTrue(Assert.java:65)
 |  at org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanSearchSpec.(OnBeanCondition.java:232)
 |  at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:93)
 |  at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45)

from spring-cloud-consul.

arun0009 avatar arun0009 commented on June 1, 2024

@spencergibb more stack below with 1.0.0.BUILD-SNAPSHOT version

notificationsapiclient_1 | java.lang.IllegalStateException: Error processing condition on org.springframework.cloud.consul.ConsulAutoConfiguration.consulProperties
notificationsapiclient_1 |  at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:58)
notificationsapiclient_1 |  at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102)
notificationsapiclient_1 |  at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:190)
notificationsapiclient_1 |  at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148)
notificationsapiclient_1 |  at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124)
notificationsapiclient_1 |  at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318)
notificationsapiclient_1 |  at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239)
notificationsapiclient_1 |  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
notificationsapiclient_1 |  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
notificationsapiclient_1 |  at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
notificationsapiclient_1 |  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
notificationsapiclient_1 |  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
notificationsapiclient_1 |  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
notificationsapiclient_1 |  at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
notificationsapiclient_1 |  at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
notificationsapiclient_1 |  at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
notificationsapiclient_1 |  at com.capitalone.api.notifications.service.NotificationsApiClient.main(NotificationsApiClient.java:61)
notificationsapiclient_1 |  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
notificationsapiclient_1 |  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
notificationsapiclient_1 |  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
notificationsapiclient_1 |  at java.lang.reflect.Method.invoke(Method.java:497)
notificationsapiclient_1 |  at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
notificationsapiclient_1 |  at java.lang.Thread.run(Thread.java:745)
notificationsapiclient_1 | Caused by: java.lang.IllegalArgumentException: @ConditionalOnMissingBean annotations must specify at least one bean (type, name or annotation)
notificationsapiclient_1 |  at org.springframework.util.Assert.isTrue(Assert.java:65)
notificationsapiclient_1 |  at org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanSearchSpec.(OnBeanCondition.java:232)
notificationsapiclient_1 |  at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:93)
notificationsapiclient_1 |  at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45)

from spring-cloud-consul.

spencergibb avatar spencergibb commented on June 1, 2024

@arun0009 can you open a new issue, this one has been closed for a while.

from spring-cloud-consul.

GuiForget avatar GuiForget commented on June 1, 2024

I'm still new to Consul so I may have confused myself but when I saw the property preferIpAddress I assumed it was a switch between hostname vs ipAddress but it seems that it (also?) toggles between node names and the actual host providing the service.

The behavior is therefore very different when you run in an environment where the Consul server is not running on the same host as your services. If you have preferIpAddress false you basically get the wrong URIs.

Here is my very basic code:

    @Autowired
    private DiscoveryClient discoveryClient;

    public void printInstances(String serviceName) throws Exception {

        List<ServiceInstance> list = discoveryClient.getInstances(serviceName);
        if (list == null) {
            System.out.format("===== Null list returned for %s%n", serviceName);
        } else {
            System.out.format("===== Found %d instances of %s%n", list.size(), serviceName);
            for (ServiceInstance serviceInstance : list) {
                System.out.println(
                        serviceInstance.getServiceId() + " -- " + serviceInstance.getUri());
            }
        }
    }

With preferIpAddress=false, the output (with hostnames simplified) is:

===== Found 2 instances of myservice
myservice -- http://consulhost:9010
myservice -- http://consulhost:9010

With preferIpAddress=true, the output is then:

===== Found 2 instances of myservice
myservice -- http://servicelhos1:9010
myservice -- http://servicehost2:9010

from spring-cloud-consul.

spencergibb avatar spencergibb commented on June 1, 2024

@GuiForget please open a new issue please, rather than comment on a closed issue.

from spring-cloud-consul.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.