java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set,

生产启动springboot报错,详细报错信息如下:

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
	at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:155)
	at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:52)
	at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locateCollection(ConfigServicePropertySourceLocator.java:170)
	at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$FastClassBySpringCGLIB$$fa44b2a.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
	at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:91)
	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:287)
	at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:164)
	at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:118)
	at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:153)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
	at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$EnhancerBySpringCGLIB$$1a5593a1.locateCollection(<generated>)
	at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:98)
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:626)
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:370)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
	at com.bmw.tsic.push.PushApp.main(PushApp.java:73)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/config/push/prod/main":  Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:746)
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:672)
	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:581)
	at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:271)
	at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:114)
	... 29 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
	at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
	at sun.net.www.http.HttpClient.New(HttpClient.java:339)
	at sun.net.www.http.HttpClient.New(HttpClient.java:357)
	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
	at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
	at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:737)
	... 33 common frames omitted

一开始,网上查了很多资料,都不符合或者说不能解决问题,没办法,还是只能靠自己,所以仔细的去研究导致报错的原因,可以看到引起报错的原因主要是由于:

 I/O error on GET request for "http://localhost:8761/config/push/prod/main"

这个错误导致的,所以直接复制 http://localhost:8761/config这句话去工程里面查找,果然找到了错误的真正原因:

原来是项目的bootstrap.yml,配置的问题,其在dev配置器中是这样的:

重点便在于http://localhost:8761/config,之后我又看到项目中还存在基于生产环境的bootstrap-prod.yml,原因便是生产环境中的配置和dev是一样的,导致报错。

所以把生产的localhost替换成项目注册中心的域名/IP即可。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: java.lang.illegalstateexception: could not locate propertysource and the fail fast property is set, failing 这个错误表示在应用程序中无法找到属性源,并且设置了快速失败属性,因此应用程序将无法启动。可能是由于配置文件缺失或配置错误导致的。需要检查应用程序的配置文件,确保所有属性源都正确配置,并且没有缺失或错误的配置。 ### 回答2: 这个错误信息是Java中的一个IllegalStateException异常,通常意味着无法找到一个属性源。这可能是因为没有正确配置属性源或者没有正确地引入依赖项。 在某些情况下,可能在应用程序运行时动态地加载属性源。如果这个属性源不能被找到,就会抛出这个异常。 另一个可能的原因是由于设置了“fail fast”属性,这意味着应用程序检测到问题后会立即停止,并抛出异常。这通常是因为开发人员希望避免由于某些问题导致代码继续运行而可能导致更严重的问题。 为了解决这个问题,可以通过以下方式来查找缺少的属性源并将其正确配置: 1)检查应用程序的配置文件,确保所有必需的属性源都已正确配置。 2)检查应用程序的依赖项,确保所有必需的依赖项都已正确引入。 3)尝试重新启动应用程序,可能会重新加载属性源并解决问题。 4)尝试取消“fail fast”属性的设置,以便应用程序在出现问题时可以继续运行并更好地确定问题的根本原因。 总之,这个错误信息提示了找不到属性源的问题,需要仔细检查配置文件和依赖项。此外,还可以通过取消“fail fast”属性的设置来便于调试。 ### 回答3: java.lang.illegalstateexception: could not locate propertysource and the fail fast property is setfailing 这个错误信息通常是在Spring框架下出现的,它是由于在应用程序启动或运行期间找不到必要的属性文件而导致的,同时也与Spring的“快速失败”机制有关。 首先,我们需要理解Spring的“属性源”概念。在Spring中,应用程序的配置信息通常存储在属性文件中,这些属性文件可以是XML、YAML或者Properties格式的文件。在应用程序启动或运行时,Spring会通过PropertySource将这些属性文件加载到内存中,这样应用程序就能从内存中读取属性文件中的配置信息。 然而,在某些情况下,当Spring尝试加载属性文件时,可能会出现找不到属性文件的错误。这通常是由于文件路径不正确、文件名错误或属性文件损坏等原因造成的。 同时,如果在应用程序中设置了“快速失败”(fail fast)机制,当Spring在加载属性文件时遇到错误,它会立即抛出异常并终止应用程序的启动或运行,这就是这个错误信息的原因。 要解决这个问题,首先需要检查应用程序中引用的属性文件路径是否正确,并确保属性文件中的键值对都是正确的。如果属性文件损坏,可以通过运行时生成新的属性文件来解决。另外,如果应用程序中设置了快速失败模式,可以考虑禁用它,以便Spring可以继续运行即使存在问题。 总之,java.lang.illegalstateexception: could not locate propertysource and the fail fast property is setfailing 这个错误信息的出现通常是由于Spring在加载属性文件时遇到错误,我们需要检查属性文件路径、格式和内容,确保它们都是正确的,并考虑禁用快速失败模式以便应用程序可以继续运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值