If the question is the same, usespring-cloud
Several microservices have been built for testing use.docker-compose
Arrange, found a problem in the process of testing:
The microservice provider project uses the variables provided by the configuration center project and uses the
@Value("${from}")
Method injection, both services rely on discovery services (Eureka
), then the micro-service provider cannot start correctly when the configuration center project is not started. At startup${from}
Variables will prompt that they do not exist, resulting in errors. If it is started locally, the configuration center project can be started first. This problem can be avoided, but it is still in use.docker-compose
How to solve the problem of dependency when arranging, or can you specify one project to start and then start other projects?
docker-compose.yml
version: '2'
services:
discover1:
image: zlikun/eureka:1.0.0
container_name: discover1
ports:
- "8761:8761"
environment:
- spring.profiles.active=prod
- eureka.client.service-url.defaultZone=http://discover2:8761/eureka/,http://discover3:8761/eureka/
discover2:
image: zlikun/eureka:1.0.0
container_name: discover2
ports:
- "8762:8761"
environment:
- spring.profiles.active=prod
- eureka.client.service-url.defaultZone=http://discover1:8761/eureka/,http://discover3:8761/eureka/
discover3:
image: zlikun/eureka:1.0.0
container_name: discover3
ports:
- "8763:8761"
environment:
- spring.profiles.active=prod
- eureka.client.service-url.defaultZone=http://discover1:8761/eureka/,http://discover2:8761/eureka/
config1:
image: zlikun/config:1.0.0
container_name: config1
ports:
- "7001:7001"
environment:
- spring.profiles.active=prod
- eureka.client.service-url.defaultZone=http://discover1:8761/eureka/,http://discover2:8761/eureka/,http://discover3:8761/eureka/
config2:
image: zlikun/config:1.0.0
container_name: config2
ports:
- "7002:7001"
environment:
- spring.profiles.active=prod
- eureka.client.service-url.defaultZone=http://discover1:8761/eureka/,http://discover2:8761/eureka/,http://discover3:8761/eureka/
user1:
image: zlikun/user:1.0.0
container_name: user1
ports:
- "9001:9000"
environment:
- spring.profiles.active=prod
- eureka.client.service-url.defaultZone=http://discover1:8761/eureka/,http://discover2:8761/eureka/,http://discover3:8761/eureka/
user2:
image: zlikun/user:1.0.0
container_name: user2
ports:
- "9002:9000"
environment:
- spring.profiles.active=prod
- eureka.client.service-url.defaultZone=http://discover1:8761/eureka/,http://discover2:8761/eureka/,http://discover3:8761/eureka/
Testing engineering
Error message
2017-08-16 15:47:28.474 WARN 12932 --- [ main] lientConfigServiceBootstrapConfiguration : Could not locate configserver via discovery
java.lang.IllegalStateException: No instances found of configserver (config)
at org.springframework.cloud.config.client.ConfigServerInstanceProvider.getConfigServerInstance(ConfigServerInstanceProvider.java:25) ~[spring-cloud-config-client-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.refresh(DiscoveryClientConfigServiceBootstrapConfiguratio n.java:80) [spring-cloud-config-client-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.startup(DiscoveryClientConfigServiceBootstrapConfiguratio n.java:66) [spring-cloud-config-client-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_102]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_102]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_102]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:256) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at com.zlikun.sc.UserApplication.main(UserApplication.java:12) [classes/:na]
2017-08-16 15:47:28.513 INFO 12932 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9000 (http)
2017-08-16 15:47:28.513 INFO 12932 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9000
2017-08-16 15:47:28.517 INFO 12932 --- [ main] com.zlikun.sc.UserApplication : Started UserApplication in 8.029 seconds (JVM running for 8.768)
The exception information here is the exception thrown when I started the micro-service provider when the configuration center was shut down during local debugging. I have two questions:
- How to Avoid Configuration Dependency (From
spring-cloud
Start on your own) - How to deal with
docker-compose
The container startup sequence during layout (aboutdocker-compose
I am a beginner, so I don’t know much about it yet.
Split docker-compose file
Separate the basic platforms such as the configuration center. After all, these may only be started once in the entire application cycle.