我正在尝试在我的eureka发现服务器中注册spring-cloud配置服务器,但是我遇到此错误:
java.lang.IllegalStateException:找不到configserver(配置服务器)的实例
application.yml(配置服务器):
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(尤里卡服务器):
spring:
application:
name: eureka-server
server:
port: 1111
eureka:
client:
registerWithEureka: false
fetchRegistry: false
service-url:
defaultZone: http://localhost:1111/eureka/
bootstrap.yml(Eureka客户端):
spring:
application:
name: eureka-client
cloud:
config:
discovery:
enabled: true
service-id: config-server
eureka-client.yml(在配置服务器存储库中找到的eureka-client配置):
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文件,以及下方的Application类和pom文件:
ConfigServerApplication:
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
用于ConfigServer的pom.xml:
<?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
如果任何人知道我在做什么错,那么任何帮助都会很棒。谢谢。
结论
我得出的结论是,当我在笔记本电脑上完成相同的项目并且项目运行得很好时,我的项目文件或计算机出现了问题。我不知道哪里出了问题
答案 0 :(得分:0)
嘿,我的设置遇到了同样的问题。
我改变了
spring.application.name: config-server
..至
spring.application.name: configserver
问题消失了。我知道这很奇怪,但是它为我完成了工作。
答案 1 :(得分:0)
有时(yaml / properties文件中不存在(spring.cloud.config.discovery.serviceId)此属性时,会出现此错误。 我收到相同的“找不到配置服务器实例”错误。当我使用“ serviceId”时,它得到解决。