Spring Cloud Kubernetes - 启用配置重新加载后,Spring启动无法启动-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

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

2019-01-11 13:54:45 7388 2

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

这是我的主要课程:

@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.enabled为false一切正常,则会读取并使用configmap。现在我的目标是在configmap更改时重新加载配置,但是获得上面看到的异常。我可以/actuator/refresh手动调用,所以我不认为缺少刷新端点的可用性。

取消 提交回答
全部回答(2)
  • 1154792673968589
    2019-07-17 23:25:18

    800多人看问题 就是没有一个答案

    0 0
  • k8s小能手
    2019-07-17 23:25:18

    如果你设置它就会启动 management.endpoint.restart.enabled=true

    该消息告诉您它无法加载RestartEndpointbean。没有创建,因为有两种方式可以加载并且满足下层:

    未加载'RestartEndpointWithIntegrationConfiguration'中的Bean方法'restartEndpoint',因为@ConditionalOnClass未找到所需的类'org.springframework.integration.monitor.IntegrationMBeanExporter'
    那么你没有使用弹簧集成,所以我猜你不想要这条路 - 你想要另一条路。

    未加载'RestartEndpointWithoutIntegrationConfiguration'中的Bean方法'restartEndpointWithoutIntegration',因为@ConditionalOnEnabledEndpoint没有找到属性management.endpoint.restart.enabled,因此使用端点默认值
    所以我们需要设置 management.endpoint.restart.enabled=true,这也是在官方重装示例项目中设置的。如果不设置它,我们将不会加载我们需要的RestartEndpoint bean

    0 0
添加回答
相关问答

40

回答

[@徐雷frank][¥20]什么是JAVA的平台无关性

大河人家 2018-10-29 23:55:20 144790浏览量 回答数 40

162

回答

惊喜翻倍:免费ECS+免费环境配置~!(ECS免费体验6个月活动3月31日结束)

豆妹 2014-10-29 17:52:21 226290浏览量 回答数 162

145

回答

【新手入门】云服务器linux使用手册

fanyue88888 2012-11-26 17:14:18 157796浏览量 回答数 145

8

回答

OceanBase 使用动画(持续更新)

mq4096 2019-02-20 17:16:36 337144浏览量 回答数 8

13

回答

[@饭娱咖啡][¥20]我想知道 Java 关于引用那一块的知识

心意乱 2018-10-31 18:44:12 142498浏览量 回答数 13

111

回答

OSS存储服务-客户端工具

newegg11 2012-05-17 15:37:18 295731浏览量 回答数 111

22

回答

爬虫数据管理【问答合集】

我是管理员 2018-08-10 16:37:41 147297浏览量 回答数 22

18

回答

阿里云开放端口权限

xcxx 2016-07-20 15:03:33 646929浏览量 回答数 18

31

回答

[@倚贤][¥20]刚学完html/css/js的新手学习servlet、jsp需要注意哪些问题?

弗洛伊德6 2018-10-27 21:52:43 146097浏览量 回答数 31

249

回答

阿里云LNAMP(Linux + Nginx + Apache + MySQL + PHP)环境一键安装脚本

云代维 2014-02-14 15:26:06 305738浏览量 回答数 249
+关注
k8s小能手
整合最优质的专家资源和技术资料,问答解疑
26
文章
620
问答
问答排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载