ThomasVitale / cloud-native-spring-in-action

🍃 Code samples and projects from the book "Cloud Native Spring in Action - With Spring Boot and Kubernetes" (Manning)
https://www.manning.com/books/cloud-native-spring-in-action
Apache License 2.0
426 stars 257 forks source link

Chapter13 end: connection error from edge-service #36

Closed lucamoroldo closed 10 months ago

lucamoroldo commented 1 year ago

Hi, I wanted to test the tracing functionality by calling the edge-service /books endpoint. However, when running the edge-service (docker-compose up edge-service), the service startup fails with the logs attached. It seems that it cannot resolve "host.docker.internal". I'm running the services on WSL (Windows 11).

Note that all the other dependencies are running (grafana, keycloak, etc) and by running "http :8080/realms/PolarBookshop" I get a valid response containing the public key.

Edge service logs:

edge-service  | 2023-03-09 12:13:30.094  WARN [edge-service,,] 1 --- [           main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfiguration': Unsatisfied dependency expressed through method 'setAdapterRegistry' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration$EnableWebFluxConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientImportSelector$OAuth2ClientWebFluxSecurityConfiguration': Unsatisfied dependency expressed through method 'setAuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayReactiveOAuth2AuthorizedClientManager' defined in class path resource [org/springframework/cloud/gateway/config/GatewayReactiveOAuth2AutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayReactiveOAuth2AuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientConfigurations$ReactiveClientRegistrationRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  | 2023-03-09 12:13:30.136  INFO [edge-service,,] 1 --- [           main] ConditionEvaluationReportLoggingListener :
edge-service  |
edge-service  | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
edge-service  | 2023-03-09 12:13:30.194 ERROR [edge-service,,] 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
edge-service  |
edge-service  | org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfiguration': Unsatisfied dependency expressed through method 'setAdapterRegistry' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration$EnableWebFluxConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientImportSelector$OAuth2ClientWebFluxSecurityConfiguration': Unsatisfied dependency expressed through method 'setAuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayReactiveOAuth2AuthorizedClientManager' defined in class path resource [org/springframework/cloud/gateway/config/GatewayReactiveOAuth2AutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayReactiveOAuth2AuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientConfigurations$ReactiveClientRegistrationRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:767) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:719) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.3.jar:2.7.3]
edge-service  |         at com.polarbookshop.edgeservice.EdgeServiceApplication.main(EdgeServiceApplication.java:11) ~[classes/:na]
edge-service  |         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
edge-service  |         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
edge-service  |         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
edge-service  |         at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
edge-service  |         at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[workspace/:na]
edge-service  |         at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[workspace/:na]
edge-service  |         at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[workspace/:na]
edge-service  |         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[workspace/:na]
edge-service  | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration$EnableWebFluxConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientImportSelector$OAuth2ClientWebFluxSecurityConfiguration': Unsatisfied dependency expressed through method 'setAuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayReactiveOAuth2AuthorizedClientManager' defined in class path resource [org/springframework/cloud/gateway/config/GatewayReactiveOAuth2AutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayReactiveOAuth2AuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientConfigurations$ReactiveClientRegistrationRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:767) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:719) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:410) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:759) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         ... 28 common frames omitted
edge-service  | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientImportSelector$OAuth2ClientWebFluxSecurityConfiguration': Unsatisfied dependency expressed through method 'setAuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayReactiveOAuth2AuthorizedClientManager' defined in class path resource [org/springframework/cloud/gateway/config/GatewayReactiveOAuth2AutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayReactiveOAuth2AuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientConfigurations$ReactiveClientRegistrationRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:767) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:719) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1609) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1573) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1462) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1349) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:759) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         ... 51 common frames omitted
edge-service  | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayReactiveOAuth2AuthorizedClientManager' defined in class path resource [org/springframework/cloud/gateway/config/GatewayReactiveOAuth2AutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayReactiveOAuth2AuthorizedClientManager' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientConfigurations$ReactiveClientRegistrationRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1609) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1573) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1462) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1349) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:759) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         ... 68 common frames omitted
edge-service  | Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientConfigurations$ReactiveClientRegistrationRepositoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         ... 84 common frames omitted
edge-service  | Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  |         at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         ... 98 common frames omitted
edge-service  | Caused by: java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of "http://host.docker.internal:8080/realms/PolarBookshop"
edge-service  |         at org.springframework.security.oauth2.client.registration.ClientRegistrations.getBuilder(ClientRegistrations.java:220) ~[spring-security-oauth2-client-5.7.3.jar:5.7.3]
edge-service  |         at org.springframework.security.oauth2.client.registration.ClientRegistrations.fromIssuerLocation(ClientRegistrations.java:144) ~[spring-security-oauth2-client-5.7.3.jar:5.7.3]
edge-service  |         at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getBuilderFromIssuerIfPossible(OAuth2ClientPropertiesRegistrationAdapter.java:83) ~[spring-boot-autoconfigure-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistration(OAuth2ClientPropertiesRegistrationAdapter.java:59) ~[spring-boot-autoconfigure-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.lambda$getClientRegistrations$0(OAuth2ClientPropertiesRegistrationAdapter.java:53) ~[spring-boot-autoconfigure-2.7.3.jar:2.7.3]
edge-service  |         at java.base/java.util.HashMap.forEach(Unknown Source) ~[na:na]
edge-service  |         at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(OAuth2ClientPropertiesRegistrationAdapter.java:52) ~[spring-boot-autoconfigure-2.7.3.jar:2.7.3]
edge-service  |         at org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientConfigurations$ReactiveClientRegistrationRepositoryConfiguration.clientRegistrationRepository(ReactiveOAuth2ClientConfigurations.java:56) ~[spring-boot-autoconfigure-2.7.3.jar:2.7.3]
edge-service  |         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
edge-service  |         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
edge-service  |         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
edge-service  |         at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
edge-service  |         at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.22.jar:5.3.22]
edge-service  |         ... 99 common frames omitted
edge-service  | Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://host.docker.internal:8080/realms/PolarBookshop/.well-known/openid-configuration": Connection timed out; nested exception is java.net.ConnectException: Connection timed out
edge-service  |         at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785) ~[spring-web-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:670) ~[spring-web-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.security.oauth2.client.registration.ClientRegistrations.lambda$oidc$0(ClientRegistrations.java:155) ~[spring-security-oauth2-client-5.7.3.jar:5.7.3]
edge-service  |         at org.springframework.security.oauth2.client.registration.ClientRegistrations.getBuilder(ClientRegistrations.java:208) ~[spring-security-oauth2-client-5.7.3.jar:5.7.3]
edge-service  |         ... 111 common frames omitted
edge-service  | Caused by: java.net.ConnectException: Connection timed out
edge-service  |         at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
edge-service  |         at java.base/sun.nio.ch.Net.connect(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.nio.ch.Net.connect(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source) ~[na:na]
edge-service  |         at java.base/java.net.Socket.connect(Unknown Source) ~[na:na]
edge-service  |         at java.base/java.net.Socket.connect(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.NetworkClient.doConnect(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.http.HttpClient.<init>(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.http.HttpClient.New(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.http.HttpClient.New(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) ~[na:na]
edge-service  |         at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) ~[na:na]
edge-service  |         at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76) ~[spring-web-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66) ~[spring-web-5.3.22.jar:5.3.22]
edge-service  |         at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776) ~[spring-web-5.3.22.jar:5.3.22]
edge-service  |         ... 114 common frames omitted
edge-service  |
edge-service  |
edge-service  | Native Memory Tracking:
edge-service  |
edge-service  | Total: reserved=13113770919, committed=366080935
edge-service  |        malloc: 68260775 #387651
edge-service  |        mmap:   reserved=13045510144, committed=297820160
edge-service  |
edge-service  | -                 Java Heap (reserved=12087984128, committed=167772160)
edge-service  |                             (mmap: reserved=12087984128, committed=167772160)
edge-service  |
edge-service  | -                     Class (reserved=122767701, committed=8735061)
edge-service  |                             (classes #12613)
edge-service  |                             (  instance classes #11714, array classes #899)
edge-service  |                             (malloc=1132885 #24697)
edge-service  |                             (mmap: reserved=121634816, committed=7602176)
edge-service  |                             (  Metadata:   )
edge-service  |                             (    reserved=50331648, committed=48365568)
edge-service  |                             (    used=48128608)
edge-service  |                             (    waste=236960 =0.49%)
edge-service  |                             (  Class space:)
edge-service  |                             (    reserved=121634816, committed=7602176)
edge-service  |                             (    used=7390552)
edge-service  |                             (    waste=211624 =2.78%)
edge-service  |
edge-service  | -                    Thread (reserved=36903512, committed=2071128)
edge-service  |                             (thread #36)
edge-service  |                             (stack: reserved=36786176, committed=1953792)
edge-service  |                             (malloc=66256 #274)
edge-service  |                             (arena=51080 #87)
edge-service  |
edge-service  | -                      Code (reserved=255292808, committed=22599048)
edge-service  |                             (malloc=1660296 #7376)
edge-service  |                             (mmap: reserved=253632512, committed=20938752)
edge-service  |
edge-service  | -                        GC (reserved=505036284, committed=62684668)
edge-service  |                             (malloc=22523388 #6084)
edge-service  |                             (mmap: reserved=482512896, committed=40161280)
edge-service  |
edge-service  | -                  Compiler (reserved=17065000, committed=17065000)
edge-service  |                             (malloc=77088 #845)
edge-service  |                             (arena=16987912 #20)
edge-service  |
edge-service  | -                  Internal (reserved=2229004, committed=2229004)
edge-service  |                             (malloc=2192140 #18525)
edge-service  |                             (mmap: reserved=36864, committed=36864)
edge-service  |
edge-service  | -                     Other (reserved=8224, committed=8224)
edge-service  |                             (malloc=8224 #3)
edge-service  |
edge-service  | -                    Symbol (reserved=14049720, committed=14049720)
edge-service  |                             (malloc=12993792 #310555)
edge-service  |                             (arena=1055928 #1)
edge-service  |
edge-service  | -    Native Memory Tracking (reserved=6210840, committed=6210840)
edge-service  |                             (malloc=8408 #117)
edge-service  |                             (tracking overhead=6202432)
edge-service  |
edge-service  | -        Shared class space (reserved=12582912, committed=10981376)
edge-service  |                             (mmap: reserved=12582912, committed=10981376)
edge-service  |
edge-service  | -               Arena Chunk (reserved=530000, committed=530000)
edge-service  |                             (malloc=530000)
edge-service  |
edge-service  | -                   Tracing (reserved=345, committed=345)
edge-service  |                             (malloc=345 #9)
edge-service  |
edge-service  | -                 Arguments (reserved=169, committed=169)
edge-service  |                             (malloc=169 #5)
edge-service  |
edge-service  | -                    Module (reserved=286000, committed=286000)
edge-service  |                             (malloc=286000 #2292)
edge-service  |
edge-service  | -                 Safepoint (reserved=8192, committed=8192)
edge-service  |                             (mmap: reserved=8192, committed=8192)
edge-service  |
edge-service  | -           Synchronization (reserved=115464, committed=115464)
edge-service  |                             (malloc=115464 #811)
edge-service  |
edge-service  | -            Serviceability (reserved=1034104, committed=1034104)
edge-service  |                             (malloc=1034104 #9911)
edge-service  |
edge-service  | -                 Metaspace (reserved=50533040, committed=48566960)
edge-service  |                             (malloc=201392 #107)
edge-service  |                             (mmap: reserved=50331648, committed=48365568)
edge-service  |
edge-service  | -      String Deduplication (reserved=704, committed=704)
edge-service  |                             (malloc=704 #8)
edge-service  |
edge-service  | -           Object Monitors (reserved=1132768, committed=1132768)
edge-service  |                             (malloc=1132768 #5446)
edge-service  |
edge-service exited with code 1
ThomasVitale commented 1 year ago

Hi @lucamoroldo, could you check if host.docker.internal can be resolved to an IP address in your WSL2 environment?

$ host host.docker.internal
host.docker.internal has address 127.0.0.1

That hostname should be configured automatically when installing Docker Desktop. And it should result in the following configuration in the /etc/hosts file within your WSL2 environment.

127.0.0.1    host.docker.internal

If it's not there, could you try adding that manually (vim /etc/hosts) and then try again running Edge Service?

ThomasVitale commented 10 months ago

Since there hasn't been any activity in the past few months, I'm closing this issue, but feel free to open a new one should you still have some issues about the network setup. Thanks!

ongiant commented 9 months ago

@lucamoroldo Have you solved that problem? I met the same problem too. Anyone could help me?

ongiant commented 9 months ago

Solution:

Environment

  • docker engine (not docker desktop) version: 24.0.7
  • OS: Manjaro Linux
  • Steps

    1. You should add host.docker.internal to /etc/hosts. Your /etc/hosts file on your host machine should looks like this:
      
      127.0.0.1  localhost  host.docker.internal
      
      rather than this:
      
      127.0.0.1 localhost
      127.0.0.1 host.docker.internal
      
    2. Add host.docker.internal to no_proxy and NO_PROXY environment varaible (~/.bashrc or ~/.zshrc on host machine).
    3. Add host.docker.internal to proxy Exceptions in your host Chrome browser. It should look like host.docker.internal,*.yahoo.com
    4. Your final docker-compose.yml file should look like this (Note the addition of host.docker.internal:host-gateway in the extra_hosts section for both catalog_service and edge-service):
      docker-compose.yml
      
      version: '3.8'
      services:
        catalog-service:
          depends_on:
            - fluent-bit
            - polar-keycloak
            - polar-postgres
            - tempo
          image: catalog-service
          container_name: catalog-service
          ports:
            - '9001:9001'
            - '8001:8001'
          environment:
            - BPL_JVM_THREAD_COUNT=50
            - BPL_DEBUG_ENABLED=true
            - BPL_DEBUG_PORT=8001
            - >-
              JAVA_TOOL_OPTIONS=-javaagent:/workspace/BOOT-INF/lib/opentelemetry-javaagent-1.32.0.jar
            - OTEL_SERVICE_NAME=catalog-service
            - 'OTEL_EXPORTER_OTLP_ENDPOINT=http://tempo:4317'
            - OTEL_METRICS_EXPORTER=none
            - 'SPRING_CLOUD_CONFIG_URI=http://config-service:8888'
            - >-
              SPRING_DATASOURCE_URL=jdbc:postgresql://polar-postgres:5432/polardb_catalog
            - SPRING_PROFILES_ACTIVE=testdata
            - >-
              SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI=http://host.docker.internal:8080/realms/PolarBookshop
          extra_hosts:
            - 'host.docker.internal:host-gateway'
          logging:
            driver: fluentd
            options:
              fluentd-address: '127.0.0.1:24224'
        edge-service:
          depends_on:
            - fluent-bit
            - polar-keycloak
            - polar-redis
            - polar-ui
            - tempo
          image: edge-service
          container_name: edge-service
          ports:
            - '9000:9000'
            - '8000:8000'
          environment:
            - BPL_DEBUG_ENABLED=true
            - BPL_DEBUG_PORT=8000
            - 'CATALOG_SERVICE_URL=http://catalog-service:9001'
            - >-
              JAVA_TOOL_OPTIONS=-javaagent:/workspace/BOOT-INF/lib/opentelemetry-javaagent-1.32.0.jar
            - OTEL_SERVICE_NAME=edge-service
            - 'OTEL_EXPORTER_OTLP_ENDPOINT=http://tempo:4317'
            - OTEL_METRICS_EXPORTER=none
            - 'ORDER_SERVICE_URL=http://order-service:9002'
            - 'SPA_URL=http://polar-ui:9004'
            - 'SPRING_CLOUD_CONFIG_URI=http://config-service:8888'
            - SPRING_REDIS_HOST=polar-redis
            - >-
              SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_ISSUER_URI=http://host.docker.internal:8080/realms/PolarBookshop
          extra_hosts:
            - 'host.docker.internal:host-gateway'
          logging:
            driver: fluentd
            options:
              fluentd-address: '127.0.0.1:24224'
        polar-keycloak:
          image: 'quay.io/keycloak/keycloak:23.0'
          container_name: polar-keycloak
          command: start-dev --import-realm
          volumes:
            - './keycloak:/opt/keycloak/data/import'
          environment:
            - KEYCLOAK_ADMIN=user
            - KEYCLOAK_ADMIN_PASSWORD=password
          ports:
            - '8080:8080'
      

    In the end