欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

2020-11-27

程序员文章站 2022-12-07 19:49:16
Spring Cloud Config 客户端启动错误 FAQJava HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended2020-11-27 22:35:10.784 INFO 25140 --- [ main] trationDelegate$BeanPostP...

Spring Cloud Config 客户端启动错误(Fetching config from server at : http://12) FAQ

Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2020-11-27 22:35:10.784  INFO 25140 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.retry.annotation.RetryConfiguration' of type [org.springframework.retry.annotation.RetryConfiguration$$EnhancerBySpringCGLIB$$3fcf4047] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-11-27 22:35:10.790  INFO 25140 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.4.RELEASE)

2020-11-27 22:35:12.021  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:13.224  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:14.460  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:15.939  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:17.699  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:19.796  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:22.300  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:25.309  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:28.916  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:33.228  INFO 25140 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://127.0.0.1:6030/
2020-11-27 22:35:33.254 ERROR 25140 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
	at org.springframework.amqp.rabbit.config.StatelessRetryOperationsInterceptorFactoryBean.lambda$createRecoverer$0(StatelessRetryOperationsInterceptorFactoryBean.java:69) ~[spring-rabbit-2.2.3.RELEASE.jar:2.2.3.RELEASE]
	at org.springframework.retry.interceptor.RetryOperationsInterceptor$ItemRecovererCallback.recover(RetryOperationsInterceptor.java:141) ~[spring-retry-1.2.5.RELEASE.jar:na]
	at org.springframework.retry.support.RetryTemplate.handleRetryExhausted(RetryTemplate.java:512) ~[spring-retry-1.2.5.RELEASE.jar:na]
	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:351) ~[spring-retry-1.2.5.RELEASE.jar:na]
	at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:180) ~[spring-retry-1.2.5.RELEASE.jar:na]
	at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:115) ~[spring-retry-1.2.5.RELEASE.jar:na]
	at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:153) ~[spring-retry-1.2.5.RELEASE.jar:na]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) ~[spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$EnhancerBySpringCGLIB$$e927a707.locate(<generated>) ~[spring-cloud-config-client-2.2.0.RELEASE.jar:2.2.0.RELEASE]
	at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:98) ~[spring-cloud-context-2.2.0.RELEASE.jar:2.2.0.RELEASE]
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:626) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:370) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.4.RELEASE.jar:2.2.4.RELEASE]
	at com.ztf.service.a.ServiceAApplication.main(ServiceAApplication.java:24) ~[classes/:na]

Disconnected from the target VM, address: '127.0.0.1:58803', transport: 'socket'

Process finished with exit code 1

config客户端启动总是报空指针异常

     试便各种方法终无解决,把“StatelessRetryOperationsInterceptorFactoryBean”源码读了一遍也没有找到解决问题的办法。对着“Fetching config from server at : http://127.0.0.1:6030/”一直发愣想。自我对话后得到解决:

经验:难道是config服务端没有启动(其实已经启动服务了而且是正常的很)

自己:已经启动了

经验:提示信息“Fetching config from server at : http://127.0.0.1:6030/”像是在说config客户端无法连接的服务端,是不是yml配置文件问题呀!

spring:
  cloud:
    config:
      #  Config Server 地址,有如下两种方式:
      # 1. 采用直接访问config服务的方式
      # uri: http://127.0.0.1:6030
      # 2. 采用服务注册中心的服务id
      discovery:
        enabled: true
        service-id: service-config
      # 配置文件的{application}部分
      name: service-a
      # 配置文件的{profile}
      profile: dev
      # gitde 分支
      label: rewloc
      #是否启动快速失败功能,功能开启则优先判断config server是否正常(必须放到bootstrap文件中)
      fail-fast: true

自己:于是乎,把上面的配置文件检查了N遍后,没有发现任务配置上的问题。

经验:看到“org.springframework.retry.interceptor.RetryOperationsInterceptor$ItemRecovererCallback.recover(RetryOperationsInterceptor.java:141)”提示,难道是自定义“RetryConfiguration”类没有加载,看到这个类的时候发现在类名上面怎么没有“@Configuration”注解,给这个类加上注解试试吧!

package com.ztf.service.a.config;

import org.springframework.amqp.rabbit.config.RetryInterceptorBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;

/**
 * 类描述:配置spring cloud config的超时、重试配置类
 * <pre>
 *     此类需要在/resource/META-INF/spring.factories文件中添加如下配置,方可加载此类。
 *      org.springframework.cloud.bootstrap.BootstrapConfiguration=com.ztf.service.a.config.RetryConfiguration
 * </pre>
 *
 * @author Rewloc
 * @version 1.0
 * @email luhaopeng2005@126.com
 * @date 2020/9/20 22:33
 * @since JDK 14
 */
public class RetryConfiguration {

    /**
     * 功能描述:
     *
     * @return spring cloud config的超时、重试操作的配置类
     * @auther 鲁浩鹏  Lu Haopeng
     * @date 2020/11/23 22:49
     */
    @Bean
    @ConditionalOnMissingBean(name = "configServerRetryInterceptor")
    public RetryOperationsInterceptor configServerRetryInterceptor() {
        return RetryInterceptorBuilder.stateless()
                //#最初重试间隔为 1000 毫秒 #每次重试失败后,重试间隔所增加的倍数 #最长重试间隔为 5000 毫秒
                .backOffOptions(1000, 1.2, 5000)
                //#最多重试 10 次
                .maxAttempts(10)
                .build();
    }
}

自己:“RetryConfiguration”这个类不是在“/resources/META-INF/spring.factories"文件中配置过了吗?

org.springframework.cloud.bootstrap.BootstrapConfiguration=com.ztf.service.a.config.RetryConfiguration

经验:对呀!!!根据提示我能肯定是config客户端连接不上config服务端

自己:我还是去看看config服务端服务吧!config服务端就一个启动类,有什么问题呀!

2020-11-27

经验:是不是启动类出问题了,比如没有加载config服务之类的。

package com.ztf.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

/**
 * 类描述:配置中心服务启动类
 *
 * @author Rewloc
 * @version 1.0
 * @email luhaopeng2005@126.com
 * @date 2020/8/21 17:43
 * @since JDK 14
 */
@SpringBootApplication
public class ConfigApplication {

    /**
     * 功能描述: 程序入口
     *
     * @param args 参数
     * @auther 鲁浩鹏  Lu Haopeng
     * @date 2020/8/21 17:54
     */
    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

自己:这个启动类和其他微服务启动类没有上面区别呀!还是上网看看吧!CSDN、百度、码云、开源中国中寻找良药。在一篇博客中偶尔看到需要在启动类上面加上“@EnableConfigServer”注解,病重乱投医,加上试一下吧!启动config服务端,在启动config客户端,哇塞!不报错了!

@EnableConfigServer注解作用

        从字面意思上不难理解,该注解是配置config服务标识的注解类。根据我个人经验得知,这个注解是将spring cloud中的微服务标识成config服务端的注解,如果不加上此注解那么spring cloud config就没有服务端,当其客户端启动时由于需要检测config服务端是否活着而报上面(最上面)的错误信息。

求打赏安慰

2020-11-27                                                       2020-11-27

本文地址:https://blog.csdn.net/lhp3000/article/details/110249125