首页 > 解决方案 > spring cloud config客户端立即启动和停止

问题描述

我正在尝试使用此链接构建基本的 Spring Boot 云配置服务器和客户端应用程序。
配置服务器启动时没有任何问题,但是当我启动配置客户端时它会启动然后立即被杀死。它还可以根据日志访问配置服务器,但有些可疑。我也试过debug=true了,但没有具体的日志。

以下是 ConfigClient 类

package com.consul.client.ConsulClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

@SpringBootApplication
public class ConsulClientApplication {

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

    @Autowired
    public void setEnv(Environment e) {
        System.out.println(e.getProperty("msg"));
    }

}

下面是 bootstrap.properties 文件

server.port=8081
spring.cloud.config.uri=http://localhost:9081
spring.application.name=client-config
debug=true
management.security.enabled=false

和启动日志如下

2020-03-23 00:09:37.048  INFO 1166 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9081
2020-03-23 00:09:38.154  INFO 1166 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=client-config, profiles=[dev], label=null, version=14a9dd2ad6b13bb2215de9f0945f48dc15e2f10e, state=null
2020-03-23 00:09:38.155  INFO 1166 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://github.com/jagginarendra/configserver/client-config-dev.properties'}, BootstrapPropertySource {name='bootstrapProperties-https://github.com/jagginarendra/configserver/client-config.properties'}]
2020-03-23 00:09:38.164  INFO 1166 --- [           main] c.c.c.C.ConsulClientApplication          : The following profiles are active: dev
2020-03-23 00:09:38.470  INFO 1166 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=9f0269c4-90eb-309e-8c49-d7fc7be3daa5
this is dev enc
2020-03-23 00:09:38.600  INFO 1166 --- [           main] c.c.c.C.ConsulClientApplication          : Started ConsulClientApplication in 7.314 seconds (JVM running for 7.802)

Process finished with exit code 0

标签: javaspringspring-bootspring-cloud-configspring-cloud-config-server

解决方案


推荐阅读