Spring Cloud Kubernetes-启用配置重新加载后,Spring Boot无法启动

米格尔·里贝罗(Miguel Ribeiro)

我有这个演示项目,它打印从配置读取的标签。

这是我的主要课程:

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class DemoApplication {

    private MyConfig config;
    private DiscoveryClient discoveryClient;

    @Autowired
    public DemoApplication(MyConfig config, DiscoveryClient discoveryClient) {
        this.config = config;
        this.discoveryClient = discoveryClient;
    }

    @RequestMapping("/")
    public String info() {
        return config.getMessage();
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @RequestMapping("/services")
    public String services() {
        StringBuilder b = new StringBuilder();
        discoveryClient.getServices().forEach((s) -> b.append(s).append(" , "));
        return b.toString();
    }

}

MyConfig类是:

@Configuration
@ConfigurationProperties(prefix = "bean")
public class MyConfig {

    private String message = "a message that can be changed live";

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

bootstrap.properties包含以下内容:

spring.application.name=demo
spring.cloud.kubernetes.config.name=demo
spring.cloud.kubernetes.config.enabled=true
spring.cloud.kubernetes.config.namespace=default
spring.cloud.kubernetes.reload.enabled=true
spring.cloud.kubernetes.reload.monitoring-config-maps=true
spring.cloud.kubernetes.reload.strategy=refresh
spring.cloud.kubernetes.reload.mode=event
management.endpoint.refresh.enabled=true
management.endpoints.web.exposure.include=*

和依赖项build.gradle

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.cloud:spring-cloud-starter-kubernetes:+")
    compile("org.springframework.cloud:spring-cloud-starter-kubernetes-config:+")
    testCompile('org.springframework.boot:spring-boot-starter-test')
    runtime("org.springframework.boot:spring-boot-properties-migrator")
}

我正在创建ConfigMap,kubectl create -f configmap-demo.yml内容如下:

apiVersion: v1
kind: ConfigMap
metadata:
  name: demo
data:
    bean.message: This is an info from k8

在Kubernetes中进行部署时,在Spring Boot启动时出现以下错误:

2019-01-02 13:41:41.462  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e13002af] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

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

2019-01-02 13:41:41.940  INFO 1 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: ConfigMapPropertySource {name='configmap.demo.default'}
2019-01-02 13:41:41.942  INFO 1 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: SecretsPropertySource {name='secrets.demo.default'}
2019-01-02 13:41:42.030  INFO 1 --- [           main] com.example.demo.DemoApplication         : The following profiles are active: kubernetes
2019-01-02 13:41:43.391  INFO 1 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=416ee750-8ebb-365d-9114-12b51acaa1e0
2019-01-02 13:41:43.490  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e13002af] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-02 13:41:43.917  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-01-02 13:41:43.952  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-01-02 13:41:43.953  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.13
2019-01-02 13:41:43.969  INFO 1 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2019-01-02 13:41:44.156  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-01-02 13:41:44.157  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2033 ms
2019-01-02 13:41:44.957  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-01-02 13:41:45.353  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'propertyChangeWatcher' defined in class path resource [org/springframework/cloud/kubernetes/config/reload/ConfigReloadAutoConfiguration$ConfigReloadAutoConfigurationBeans.class]: Unsatisfied dependency expressed through method 'propertyChangeWatcher' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configurationUpdateStrategy' defined in class path resource [org/springframework/cloud/kubernetes/config/reload/ConfigReloadAutoConfiguration$ConfigReloadAutoConfigurationBeans.class]: Unsatisfied dependency expressed through method 'configurationUpdateStrategy' parameter 2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.context.restart.RestartEndpoint' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2019-01-02 13:41:45.358  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2019-01-02 13:41:45.370  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-01-02 13:41:45.398  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-02 13:41:45.612 ERROR 1 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 2 of method configurationUpdateStrategy in org.springframework.cloud.kubernetes.config.reload.ConfigReloadAutoConfiguration$ConfigReloadAutoConfigurationBeans required a bean of type 'org.springframework.cloud.context.restart.RestartEndpoint' that could not be found.

The following candidates were found but could not be injected:
        - Bean method 'restartEndpoint' in 'RestartEndpointWithIntegrationConfiguration' not loaded because @ConditionalOnClass did not find required class 'org.springframework.integration.monitor.IntegrationMBeanExporter'
        - Bean method 'restartEndpointWithoutIntegration' in 'RestartEndpointWithoutIntegrationConfiguration' not loaded because @ConditionalOnEnabledEndpoint no property management.endpoint.restart.enabled found so using endpoint default


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.cloud.context.restart.RestartEndpoint' in your configuration.

如果我设置spring.cloud.kubernetes.reload.enabledfalse一切正常,并且configmap被读取并投入使用。现在,我的目标是在configmap更改的情况下重新加载配置,但得到上面看到的异常。我可以/actuator/refresh手动调用,因此我认为这不是缺乏刷新端点的可用性。

我创建了一个演示项目,其中包含所有内容,网址https://drive.google.com/open?id=1QbP8vePALLZ2hWQJArnyxrzSySuXHKiz

瑞安·道森(Ryan Dawson)

如果您设置,它将开始 management.endpoint.restart.enabled=true

该消息告诉您无法加载RestartEndpointBean。没有创建任何内容,因为有两种加载方式,纳特对此感到满意:

  • 未加载“ RestartEndpointWithIntegrationConfiguration”中的Bean方法“ restartEndpoint”,因为@ConditionalOnClass找不到所需的类“ org.springframework.integration.monitor.IntegrationMBeanExporter”

好吧,您没有使用spring集成,所以我想您不希望这条路-您需要另一条路。

  • 未加载“ RestartEndpointWithoutIntegrationConfiguration”中的Bean方法“ restartEndpointWithoutIntegration”,因为未发现@ConditionalOnEnabledEndpoint属性,因此未使用端点默认属性。

因此,我们需要进行设置 management.endpoint.restart.enabled=true,这也在官方重载示例项目中也进行了设置如果不设置此设置,将不会加载我们需要的RestartEndpoint bean

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Cloud Kubernetes重新加载时序问题

Spring Cloud Kubernetes-Spring Boot不读取配置映射

Spring Cloud Kubernetes未加载配置映射

Java Spring Boot:无需Spring Cloud配置服务器即可重新加载配置

Spring Cloud Kubernetes ConfigMap 重新加载不起作用

在本地禁用Spring Cloud Kubernetes

Spring Cloud Kubernetes FeignClient错误

使用Kubernetes Spring Cloud多个配置映射

Spring Cloud Kubernetes:无法读取名称为configMap的内容

无法在Kubernetes中部署Spring Cloud Data Flow流

使用spring-boot:1.5.1和spring-cloud-stream时无法启动bean'inputBindingLifecycle'

Spring Cloud Kubernetes + Spring Cloud Gateway:无法找到k8s服务的实例

Spring Boot API无法启动

Spring Cloud Task无法使用RabbitMQ从Spring Cloud Stream启动

Spring Boot Cloud Kubernetes配置不适用于多个Pod

带有Spring Cloud Load Balancer的Spring Cloud Kubernetes

RabbitMQ作为Kubernetes中用于Spring Boot应用程序的Spring Cloud Bus

Spring Cloud Kubernetes,网关路由映射

Kubernetes服务发现中的Spring Cloud Gateway配置问题

Kubernetes的秘密和Spring Boot配置

Spring Boot无法在端口80上启动

Spring boot 无法在Tomcat实例中启动

Spring Boot 无法启动的未知原因

Spring Boot应用无法使用SSH启动

Spring Boot无法从Java 14启动

spring-boot无法在docker中启动

无法启动EHCache和Spring Boot

Spring Boot 应用程序无法启动?

配置spring-session-data-redis后无法启动spring-boot应用程序