Spring云配置Eureka第一种方法不起作用
我正在开发一个SpringCloudEureka微服务应用程序。我希望我的服务通过Eureka first方法连接到配置服务。微服务打包为docker容器,并通过docker compose进行部署。该应用程序由以下部分组成:Spring云配置Eureka第一种方法不起作用,spring,spring-boot,spring-cloud,microservices,netflix-eureka,Spring,Spring Boot,Spring Cloud,Microservices,Netflix Eureka,我正在开发一个SpringCloudEureka微服务应用程序。我希望我的服务通过Eureka first方法连接到配置服务。微服务打包为docker容器,并通过docker compose进行部署。该应用程序由以下部分组成: myapp服务注册表:使用Spring Cloud Eureka实现的服务注册表服务 myapp配置服务:Spring云配置服务服务器 myapp服务测试:一个示例微服务,它应该通过Eureka first方法连接到配置服务,尝试从配置服务获取其配置数据 与配置服务的连接
myapp服务注册表
:使用Spring Cloud Eureka实现的服务注册表服务myapp配置服务
:Spring云配置服务服务器myapp服务测试
:一个示例微服务,它应该通过Eureka first方法连接到配置服务,尝试从配置服务获取其配置数据李>
与配置服务的连接失败,如下所述。首先是一些配置数据:
这是myapp服务注册表的application.yml
:
server:
port: ${PORT:8761}
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
server:
port: ${MYAPP_CONFIG_SERVICE_PORT:8888}
spring:
cloud:
config:
server:
git:
uri: ${MYAPP_CONFIG_SERVICE_GIT_URI}
config:
name: myapp-config-service
# eureka service registry client
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
spring:
application:
name: myapp-service-test
cloud:
config:
discovery:
enabled: true
serviceId: myapp-config-service
这里是myapp配置服务的application.yml
:
server:
port: ${PORT:8761}
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
server:
port: ${MYAPP_CONFIG_SERVICE_PORT:8888}
spring:
cloud:
config:
server:
git:
uri: ${MYAPP_CONFIG_SERVICE_GIT_URI}
config:
name: myapp-config-service
# eureka service registry client
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
spring:
application:
name: myapp-service-test
cloud:
config:
discovery:
enabled: true
serviceId: myapp-config-service
配置服务器和客户端初始化为configserver eureka
和eureka first
中的示例:
myapp配置服务
的bootstrap.yml
是:
spring:
application:
name: myapp-config-service
cloud:
config:
discovery:
enabled: true
和myapp服务测试的application.yml
:
server:
port: ${PORT:8761}
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
server:
port: ${MYAPP_CONFIG_SERVICE_PORT:8888}
spring:
cloud:
config:
server:
git:
uri: ${MYAPP_CONFIG_SERVICE_GIT_URI}
config:
name: myapp-config-service
# eureka service registry client
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
spring:
application:
name: myapp-service-test
cloud:
config:
discovery:
enabled: true
serviceId: myapp-config-service
和myapp服务测试的bootstrap.yml
:
server:
port: ${PORT:8761}
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
server:
port: ${MYAPP_CONFIG_SERVICE_PORT:8888}
spring:
cloud:
config:
server:
git:
uri: ${MYAPP_CONFIG_SERVICE_GIT_URI}
config:
name: myapp-config-service
# eureka service registry client
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
spring:
application:
name: myapp-service-test
cloud:
config:
discovery:
enabled: true
serviceId: myapp-config-service
以下是docker compose.yml(在启动时用实际值替换env变量):
我可以通过将浏览器连接到并查看Eureka仪表板来检查Eureka是否正常工作。类似地,我测试配置服务是否工作并响应;另一方面,在上述配置中,myapp服务测试在启动时崩溃,日志如下:
-02-03 08:26:45.191 INFO 1 --- [ main] e.f.s.two.TestServiceApplication : Starting TestServiceApplication v0.0.1 on b1bc37422027 with PID 1 (/app.jar started by root in /)
2016-02-03 08:26:45.223 INFO 1 --- [ main] e.f.s.two.TestServiceApplication : No active profile set, falling back to default profiles: default
2016-02-03 08:26:45.448 INFO 1 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4d97e82d: startup date [Wed Feb 03 08:26:45 UTC 2016]; root of context hierarchy
2016-02-03 08:26:46.382 INFO 1 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-02-03 08:26:46.442 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$6b65138e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-02-03 08:26:47.089 INFO 1 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2016-02-03 08:26:48.231 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using encoding codec LegacyJacksonJson
2016-02-03 08:26:48.237 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using decoding codec LegacyJacksonJson
2016-02-03 08:26:49.171 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using encoding codec LegacyJacksonJson
2016-02-03 08:26:49.171 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using decoding codec LegacyJacksonJson
2016-02-03 08:26:49.496 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2016-02-03 08:26:49.497 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2016-02-03 08:26:49.497 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2016-02-03 08:26:49.498 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2016-02-03 08:26:49.502 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2016-02-03 08:26:49.503 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2016-02-03 08:26:49.503 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2016-02-03 08:26:49.720 WARN 1 --- [ main] com.netflix.discovery.DiscoveryClient : Can't get a response from http://localhost:8761/eureka/apps/
<...>
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.jar!/:1.19]
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.jar!/:1.19]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.3.4.jar!/:1.3.4]
<...>
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_66-internal]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_66-internal]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_66-internal]
<...>
2016-02-03 08:26:49.747 ERROR 1 --- [ main] com.netflix.discovery.DiscoveryClient : Can't contact any eureka nodes - possibly a security group issue?
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
<...>
2016-02-03 08:26:49.770 ERROR 1 --- [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MYAPP-SERVICE-TEST/b1bc37422027:myapp-service-test - was unable to refresh its cache! status = java.net.ConnectException: Connection refused
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
<...>
2016-02-03 08:26:49.785 WARN 1 --- [ main] com.netflix.discovery.DiscoveryClient : Using default backup registry implementation which does not do anything.
2016-02-03 08:26:49.810 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 10
2016-02-03 08:26:49.818 INFO 1 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2016-02-03 08:26:50.443 WARN 1 --- [ main] lientConfigServiceBootstrapConfiguration : Could not locate configserver via discovery
java.lang.RuntimeException: No matches for the virtual host name :myapp-config-service
at com.netflix.discovery.DiscoveryClient.getNextServerFromEureka(DiscoveryClient.java:782) ~[eureka-client-1.3.4.jar!/:1.3.4]
at org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration.refresh(DiscoveryClientConfigServiceBootstrapConfiguration.java:71) [spring-cloud-netflix-core-1.1.0.M3.jar!/:1.1.0.M3]
<...>
2016-02-03 08:26:50.470 INFO 1 --- [ main] e.f.s.two.TestServiceApplication : Started TestServiceApplication in 7.101 seconds (JVM running for 9.329)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.1.RELEASE)
2016-02-03 08:26:50.773 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2016-02-03 08:26:51.015 WARN 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/myapp-service-test/default":Connection refused; nested exception is java.net.ConnectException: Connection refused
<...>
2016-02-03 08:26:54.856 ERROR 1 --- [pool-5-thread-1] com.netflix.discovery.DiscoveryClient : Can't contact any eureka nodes - possibly a security group issue?
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
<...>
2016-02-03 08:26:57.272 WARN 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testTwoServiceController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: java.lang.String myapp.services.two.TestServiceController.message; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'message' in string value "${message}"
2016-02-03 08:26:57.281 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2016-02-03 08:26:57.299 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application startup failed
-02-03 08:26:45.191信息1---[main]e.f.s.two.TestServiceApplication:使用PID 1在b1bc37422027上启动TestServiceApplication v0.0.1(/app.jar由root in/启动)
2016-02-03 08:26:45.223信息1---[main]e.f.s.two.TestServiceApplication:未设置活动配置文件,返回默认配置文件:默认
2016-02-03 08:26:45.448信息1---[main]s.c.a.AnnotationConfigApplicationContext:刷新org.springframework.context.annotation。AnnotationConfigApplicationContext@4d97e82d:启动日期[Wed Feb 03 08:26:45 UTC 2016];上下文层次结构的根
2016-02-03 08:26:46.382信息1---[main]f.a.AutowiredAnnotationBeanPostProcessor:JSR-330“javax.inject.inject”注释已找到并支持自动布线
2016-02-03 08:26:46.442信息1---[main]trationlegate$BeanPostProcessorChecker:Bean类型为[class org.springframework.cloud.autoconfigure.configurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$6b65138e]的“配置属性RebinderAutoConfiguration”不符合由所有BeanPostProcessor处理的条件(例如:不符合自动代理的条件)
2016-02-03 08:26:47.089信息1---[main]o.s.c.n.eureka.InstanceInfo工厂:将初始实例状态设置为:启动
2016-02-03 08:26:48.231信息1---[main]c.n.d.provider.DiscoveryJersey provider:使用编码解码器LegacyJacksonJson
2016-02-03 08:26:48.237信息1---[main]c.n.d.provider.DiscoveryJersey provider:使用解码编解码器LegacyJacksonJson
2016-02-03 08:26:49.171信息1---[main]c.n.d.provider.DiscoveryJersey provider:使用编码解码器LegacyJacksonJson
2016-02-03 08:26:49.171信息1---[main]c.n.d.provider.DiscoveryJersey provider:使用解码编解码器LegacyJacksonJson
2016-02-03 08:26:49.496信息1---[main]com.netflix.DiscoveryClient:禁用增量属性:false
2016-02-03 08:26:49.497信息1---[main]com.netflix.DiscoveryClient:单一vip注册表刷新属性:null
2016-02-03 08:26:49.497信息1---[main]com.netflix.DiscoveryClient:Force full registry fetch:false
2016-02-03 08:26:49.498信息1---[main]com.netflix.DiscoveryClient:应用程序为空:false
2016-02-03 08:26:49.502信息1---[main]com.netflix.DiscoveryClient:注册的应用程序大小为零:true
2016-02-03 08:26:49.503信息1---[main]com.netflix.DiscoveryClient:应用程序版本为-1:true
2016-02-03 08:26:49.503信息1---[main]com.netflix.DiscoveryClient:从eureka服务器获取所有实例注册表信息
2016-02-03 08:26:49.720警告1---[main]com.netflix.discovery.DiscoveryClient:无法从http://localhost:8761/eureka/apps/
com.sun.jersey.api.client.clienthandler异常:java.net.ConnectException:连接被拒绝
在com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)~[jersey-apache-client4-1.19.jar!/:1.19]
在com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)~[jersey-client-1.19.jar!/:1.19]
在com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)~[eureka-client-1.3.4.jar!/:1.3.4]
原因:java.net.ConnectException:连接被拒绝
在java.net.PlainSocketImpl.socketConnect(本机方法)~[na:1.8.0_66-internal]
在java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)~[na:1.8.0_66-internal]
在java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)~[na:1.8.0_66-internal]
2016-02-03 08:26:49.747错误1---[main]com.netflix.DiscoveryClient:无法联系任何eureka节点-可能是安全组问题?
com.sun.jersey.api.client.clienthandler异常:java.net.ConnectException:连接被拒绝
2016-02-03 08:26:49.770错误1---[main]com.netflix.DiscoveryClient:DiscoveryClient\u MYAPP-SERVICE-TEST/b1bc374