PacktPublishing / Microservices-with-Spring-Boot-and-Spring-Cloud-Third-Edition

Microservices with Spring Boot and Spring Cloud, Third Edition
MIT License
209 stars 166 forks source link

Chapter 16 is not working... #1

Closed tintachina84 closed 1 year ago

tintachina84 commented 1 year ago

Hello.

I'm learning microservice via this contents. Thanks.

I have stepped chapter 16 but it's not working. Problem is that core microservices can't get common properties in config-repo.

I thoght I got miss something, so built your code directly but not different.

For example, if I requests config properties to config-server in Chapter14, docker exec 722feaa1c331 curl -v http://dev-usr:dev-pwd@localhost:8888/review/docker result is {"name":"review","profiles":["docker"],"label":null,"version":null,"state":null,"propertySources":[{"name":"Config resource 'file [/config-repo/review.yml]' via location 'file:/config-repo/' (document #1)","source":{"spring.config.activate.on-profile":"docker","server.port":8080,"spring.datasource.url":"jdbc:mysql://mysql/review-db"}},... propertySources is not empty.

But in Chapter16, docker exec 05e9473ea07b curl -v http://dev-usr:dev-pwd@config-server:8888/review/docker result is {"name":"review","profiles":["docker"],"label":null,"version":null,"state":null,"propertySources":[]}

So all core component can't be available because they couldn't get @Value component.

This is product-composite log: $ kubectl logs deploy/product-composite

06:58:29.032 [main] DEBUG reactor.util.Loggers - Using Slf4j logging framework

. _ _ /\ / '_ () \ \ \ \ ( ( )\ | ' | '| | ' \/ ` | \ \ \ \ \/ _)| |)| | | | | || (| | ) ) ) ) ' |__| .|| ||| |\, | / / / / =========|_|==============|__/=//// :: Spring Boot :: (v3.0.4)

2023-10-12T06:58:29.838Z INFO 1 --- [ main] m.c.p.ProductCompositeServiceApplication : Starting ProductCompositeServiceApplication v1.0.0-SNAPSHOT using Java 17.0.5 with PID 1 (/application/BOOT-INF/classes started by root in /application) 2023-10-12T06:58:29.839Z INFO 1 --- [ main] m.c.p.ProductCompositeServiceApplication : The following 1 profile is active: "docker" 2023-10-12T06:58:29.932Z INFO 1 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : http://config-server:8888 2023-10-12T06:58:29.933Z INFO 1 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Located environment: name=product-composite, profiles=[docker], label=null, version=null, state=null 2023-10-12T06:58:31.851Z INFO 1 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created. 2023-10-12T06:58:31.934Z INFO 1 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created. 2023-10-12T06:58:32.633Z INFO 1 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=526ee70c-5369-39fe-8541-9d99211bc97f 2023-10-12T06:58:34.432Z WARN 1 --- [ main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productCompositeServiceApplication': Injection of autowired dependencies failed 2023-10-12T06:58:34.531Z INFO 1 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2023-10-12T06:58:34.539Z ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productCompositeServiceApplication': Injection of autowired dependencies failed at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:487) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1408) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:961) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:917) ~[spring-context-6.0.6.jar:6.0.6] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) ~[spring-context-6.0.6.jar:6.0.6] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[spring-boot-3.0.4.jar:3.0.4] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[spring-boot-3.0.4.jar:3.0.4] at se.magnus.microservices.composite.product.ProductCompositeServiceApplication.main(ProductCompositeServiceApplication.java:88) ~[classes/:1.0.0-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[application/:na] at org.springframework.boot.loader.Launcher.launch(Launcher.java:95) ~[application/:na] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[application/:na] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[application/:na] Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'api.common.version' in value "${api.common.version}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-6.0.6.jar:6.0.6] at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-6.0.6.jar:6.0.6] at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-6.0.6.jar:6.0.6] at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-6.0.6.jar:6.0.6] at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:191) ~[spring-context-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:920) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1346) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1325) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:709) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:692) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:133) ~[spring-beans-6.0.6.jar:6.0.6] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:481) ~[spring-beans-6.0.6.jar:6.0.6] ... 25 common frames omitted

This is config-server log: $ kubectl logs deploy/config-server -f

. _ _ /\ / '_ () \ \ \ \ ( ( )\ | ' | '| | ' \/ ` | \ \ \ \ \/ _)| |)| | | | | || (| | ) ) ) ) ' |__| .|| ||| |\, | / / / / =========|_|==============|__/=//// :: Spring Boot :: (v3.0.4)

2023-10-12T06:54:00.036Z INFO 1 --- [ main] s.m.s.c.ConfigServerApplication : Starting ConfigServerApplication v1.0.0-SNAPSHOT using Java 17.0.5 with PID 1 (/application/BOOT-INF/classes started by root in /application) 2023-10-12T06:54:00.040Z INFO 1 --- [ main] s.m.s.c.ConfigServerApplication : The following 2 profiles are active: "docker", "native" 2023-10-12T06:54:02.831Z INFO 1 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=a3e32586-3934-3339-8beb-dd1a8af8149a 2023-10-12T06:54:03.341Z INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8888 (http) 2023-10-12T06:54:03.346Z INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2023-10-12T06:54:03.346Z INFO 1 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.5] 2023-10-12T06:54:03.537Z INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2023-10-12T06:54:03.538Z INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3198 ms 2023-10-12T06:54:04.734Z INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 15 endpoint(s) beneath base path '/actuator' 2023-10-12T06:54:04.754Z INFO 1 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@18c880ea, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5ac044ef, org.springframework.security.web.context.SecurityContextHolderFilter@4dd2ef54, org.springframework.security.web.header.HeaderWriterFilter@7767bd4e, org.springframework.security.web.authentication.logout.LogoutFilter@13516600, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@52621501, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@359ceb13, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1068176, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@6afbe6a1, org.springframework.security.web.access.ExceptionTranslationFilter@1304e0d7, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2c60ce47] 2023-10-12T06:54:05.339Z INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8888 (http) with context path '' 2023-10-12T06:54:05.348Z INFO 1 --- [ main] s.m.s.c.ConfigServerApplication : Started ConfigServerApplication in 12.511 seconds (process running for 16.119) 2023-10-12T06:54:05.373Z INFO 1 --- [ main] s.m.s.c.ConfigServerApplication : Serving configurations from folder: file:/config-repo 2023-10-12T06:54:14.393Z INFO 1 --- [nio-8888-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2023-10-12T06:54:14.393Z INFO 1 --- [nio-8888-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2023-10-12T06:54:14.394Z INFO 1 --- [nio-8888-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms

My environment: Windows 11 Java: 21 Docker: 24.0.6 All library and framework version are same.

This is my build commands: ./gradlew build eval $(minikube -p minikube docker-env) docker-compose build for f in kubernetes/helm/components/*; do helm dep up $f; done for f in kubernetes/helm/environments/*; do helm dep up $f; done helm install hands-on-dev-env kubernetes/helm/environments/dev-env -n hands-on --create-namespace kubectl config set-context $(kubectl config current-context) --namespace=hands-on kubectl get pods --watch

Should I change java version to 17?

magnus-larsson commented 1 year ago

Hello, and thanks for reporting this problem!

I have noticed various problems with Java 21 and Spring Boot 3.1, so I recommend to revert back to Java 17 since it is used in the book.

Let me know if that resolves your issue!

tintachina84 commented 1 year ago

Hello, again. Sorry, my bad. I made a mistake on having symbolic link. All container is running now. But gateway is not listening to my requests when I did this. curl -k https://localhost:30443/actuator/health I think NodePort setting is something wrong. Anyway this is another problem and I'll take this. Thank you!

magnus-larsson commented 1 year ago

Great! please file new issues if you get stuck on other problems!