我正在尝试向我的尤里卡发现服务器注册 spring-cloud 配置服务器,但是我遇到了此错误:
java.lang.IllegalStateException:找不到配置服务器(config-server(的实例
application.yml (config-server(:
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/danielturato/microservices-config.git
username: *******
password: *******
clone-on-start: true
server:
port: 8888
eureka:
instance:
hostname: localhost
appname: config-server
client:
service-url:
defaultZone: http://localhost:1111/eureka/
bootstrap.yml (eureka-server(:
spring:
application:
name: eureka-server
server:
port: 1111
eureka:
client:
registerWithEureka: false
fetchRegistry: false
service-url:
defaultZone: http://localhost:1111/eureka/
bootstrap.yml (eureka-client(:
spring:
application:
name: eureka-client
cloud:
config:
discovery:
enabled: true
service-id: config-server
Eureka-client.yml (Eureka-client config found on config server repo(:
eureka:
client:
service-url:
defaultZone: http://localhost:1111/eureka/
server:
port: 8081
配置服务器本身的工作方式与运行时一样,它获取 eureka 客户端的配置。但是,每隔几分钟我就会收到此错误,并且配置服务器本身永远不会注册:
java.lang.IllegalStateException: No instances found of configserver (config-server)
at org.springframework.cloud.config.client.ConfigServerInstanceProvider.getConfigServerInstances(ConfigServerInstanceProvider.java:48) ~[spring-cloud-config-client-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.refresh(DiscoveryClientConfigServiceBootstrapConfiguration.java:101) [spring-cloud-config-client-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.heartbeat(DiscoveryClientConfigServiceBootstrapConfiguration.java:92) [spring-cloud-config-client-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.onApplicationEvent(DiscoveryClientConfigServiceBootstrapConfiguration.java:82) [spring-cloud-config-client-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:408) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.cloud.netflix.eureka.CloudEurekaClient.onCacheRefreshed(CloudEurekaClient.java:123) [spring-cloud-netflix-eureka-client-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:999) [eureka-client-1.9.12.jar:1.9.12]
at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1497) [eureka-client-1.9.12.jar:1.9.12]
at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1464) [eureka-client-1.9.12.jar:1.9.12]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_211]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_211]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_211]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_211]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_211]
从这个错误来看,我可能错了,但我觉得配置服务器有问题,但我真的不确定出了什么问题。请参阅上面的application.yml文件,请参阅下面的应用程序类和pom文件:
配置服务器应用程序:
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
pom.xml for ConfigServer:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.danielturato</groupId>
<artifactId>config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>config-server</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置服务器日志:
2019-09-12 17:14:25.311 INFO 1656 --- [ main] c.d.c.ConfigServerApplication : No active profile set, falling back to default profiles: default
2019-09-12 17:14:25.983 INFO 1656 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=5638ff1e-e195-3b5c-a934-c721843f315c
2019-09-12 17:14:26.042 INFO 1656 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$3fdd8981] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-12 17:14:26.219 INFO 1656 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8888 (http)
2019-09-12 17:14:26.237 INFO 1656 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-12 17:14:26.238 INFO 1656 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-12 17:14:26.340 INFO 1656 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-12 17:14:26.340 INFO 1656 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1019 ms
2019-09-12 17:14:28.719 INFO 1656 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-12 17:14:29.162 INFO 1656 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2019-09-12 17:14:29.245 INFO 1656 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8888 (http) with context path ''
2019-09-12 17:14:29.247 INFO 1656 --- [ main] c.d.c.ConfigServerApplication : Started ConfigServerApplication in 5.097 seconds (JVM running for 6.359)
2019-09-12 17:14:47.055 INFO 1656 --- [nio-8888-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-12 17:14:47.055 INFO 1656 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-09-12 17:14:47.061 INFO 1656 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 6 ms
2019-09-12 17:14:47.769 INFO 1656 --- [nio-8888-exec-1] o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/Users/danie/AppData/Local/Temp/config-repo-6536884673987435552/eureka-client.yml
如果有人知道我做错了什么,任何帮助都会很棒。谢谢。
结论
我得出的结论是,我的项目文件或计算机有问题,因为我在笔记本电脑上完成了一个相同的项目,并且项目运行完全正常。我还不知道出了什么问题
嘿,我的设置遇到了同样的问题。
我变了spring.application.name: config-server
..自spring.application.name: configserver
问题消失了。我知道这很奇怪,但它为我做了这项工作。
有时当(spring.cloud.config.discovery.serviceId(此属性不存在于yaml/properties文件中时,您会收到此错误。 我收到相同的"找不到配置服务器的实例"错误。当我使用"服务ID"时,它得到了解决。