Spring Boot (ConfigServer) 一直在重新启动

Spring Boot (ConfigServer) is restarting all the time

我们有一个非常简单的 Spring 引导服务 (@EnableConfigServer) 运行 在 nginx 代理后面。

服务基本正常,但一直在重启(context关闭后不断启动)

在此处查看日志文件:http://pastebin.com/GErCF5x6

设置基本上只有一个 Java Class 和两个配置(bootstrap.properties 以及 application.properties)。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.context.annotation.Configuration;

/**
 * Main Application, which starts the Spring Boot context
 */
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class Application {

    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

bootstrap.properties

spring.application.name = configserver
spring.cloud.config.enabled = false
encrypt.failOnError= false
encrypt.key= secret

application.properties

# HTTP Configuration
server.port = 8888

# Management Configuration
management.context-path=/manage

# SSH Based Git-Repository
spring.cloud.config.server.git.uri=git@bitbucket.org:xyz.git
spring.cloud.config.server.git.basedir = cache/config

security.user.name=ads
security.user.password={cipher}secret2
security.basic.realm=Config Server

日志文件

11:13:47.105 [qtp1131266554-101] INFO  o.s.boot.SpringApplication - Started application in 0.176 seconds (JVM running for 245.66)
11:13:47.105 [qtp1131266554-101] INFO  o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@7709b120: startup date [Wed Apr 08 11:13:47 UTC 2015]; root of context hierarchy
11:13:47.690 [qtp1131266554-51] INFO  o.s.b.a.audit.listener.AuditListener - AuditEvent [timestamp=Wed Apr 08 11:13:47 UTC 2015, principal=ads, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@ffffe21a: RemoteIpAddress: 10.10.100.207; SessionId: null}]
11:13:48.324 [qtp1131266554-19] INFO  o.s.boot.SpringApplication - Starting application on api01.prd.rbx.xxxx.com with PID 24204 (started by ads in /home/ads/config-server)
11:13:48.328 [qtp1131266554-19] INFO  o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@473cffd3: startup date [Wed Apr 08 11:13:48 UTC 2015]; root of context hierarchy
11:13:48.332 [qtp1131266554-19] INFO  o.s.boot.SpringApplication - Started application in 0.092 seconds (JVM running for 246.887)
11:13:48.332 [qtp1131266554-19] INFO  o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@473cffd3: startup date [Wed Apr 08 11:13:48 UTC 2015]; root of context hierarchy
11:13:48.612 [qtp1131266554-55] INFO  o.s.b.a.audit.listener.AuditListener - AuditEvent [timestamp=Wed Apr 08 11:13:48 UTC 2015, principal=ads, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@ffffe21a: RemoteIpAddress: 10.10.100.207; SessionId: null}]
11:13:50.601 [qtp1131266554-77] INFO  o.s.boot.SpringApplication - Starting application on api01.prd.rbx.xxxx.com with PID 24204 (started by ads in /home/ads/config-server)
11:13:50.604 [qtp1131266554-77] INFO  o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@44330486: startup date [Wed Apr 08 11:13:50 UTC 2015]; root of context hierarchy
11:13:50.607 [qtp1131266554-77] INFO  o.s.boot.SpringApplication - Started application in 0.088 seconds (JVM running for 249.162)
11:13:50.607 [qtp1131266554-77] INFO  o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@44330486: startup date [Wed Apr 08 11:13:50 UTC 2015]; root of context hierarchy
11:13:51.831 [qtp1131266554-55] INFO  o.s.boot.SpringApplication - Starting application on api01.prd.rbx.xxxx.com with PID 24204 (started by ads in /home/ads/config-server)
11:13:51.834 [qtp1131266554-55] INFO  o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1843040d: startup date [Wed Apr 08 11:13:51 UTC 2015]; root of context hierarchy
11:13:51.840 [qtp1131266554-55] INFO  o.s.boot.SpringApplication - Started application in 0.094 seconds (JVM running for 250.395)

有什么想法,如何解决这个问题?

最好的, 弗里茨

所以,配置服务器没有重新启动。它使用一个新的 Spring 应用程序上下文并将它从 git 抓取的文件加载到一个新的上下文中,并对值进行格式化以发送回客户端。以下是来自我的配置服务器的一个客户端连接的日志。日志看起来很混乱,好像正在重新启动。

2015-04-08 12:22:52.206  INFO 85076 --- [nio-8888-exec-1] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Wed Apr 08 12:22:52 EDT 2015, principal=user, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null}]
2015-04-08 12:22:52.944  INFO 85076 --- [nio-8888-exec-2] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=Wed Apr 08 12:22:52 EDT 2015, principal=user, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null}]
2015-04-08 12:22:53.490  INFO 85076 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : Starting application on sgibb-mbp.local with PID 85076 (started by sgibb in /Users/sgibb/workspace/spring/spring-cloud-samples/configserver)
2015-04-08 12:22:53.494  INFO 85076 --- [nio-8888-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@571e4b84: startup date [Wed Apr 08 12:22:53 EDT 2015]; root of context hierarchy
2015-04-08 12:22:53.497  INFO 85076 --- [nio-8888-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-04-08 12:22:53.498  INFO 85076 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : Started application in 0.151 seconds (JVM running for 23.747)
2015-04-08 12:22:53.499  INFO 85076 --- [nio-8888-exec-1] o.s.c.c.s.NativeEnvironmentRepository    : Adding property source: file:/Users/sgibb/workspace/spring/spring-cloud-samples/configserver/target/config/foo.properties
2015-04-08 12:22:53.500  INFO 85076 --- [nio-8888-exec-1] o.s.c.c.s.NativeEnvironmentRepository    : Adding property source: file:/Users/sgibb/workspace/spring/spring-cloud-samples/configserver/target/config/application.yml
2015-04-08 12:22:53.500  INFO 85076 --- [nio-8888-exec-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@571e4b84: startup date [Wed Apr 08 12:22:53 EDT 2015]; root of context hierarchy
2015-04-08 12:22:54.090  INFO 85076 --- [nio-8888-exec-2] o.s.boot.SpringApplication               : Starting application on sgibb-mbp.local with PID 85076 (started by sgibb in /Users/sgibb/workspace/spring/spring-cloud-samples/configserver)
2015-04-08 12:22:54.096  INFO 85076 --- [nio-8888-exec-2] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@416d044c: startup date [Wed Apr 08 12:22:54 EDT 2015]; root of context hierarchy
2015-04-08 12:22:54.098  INFO 85076 --- [nio-8888-exec-2] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-04-08 12:22:54.099  INFO 85076 --- [nio-8888-exec-2] o.s.boot.SpringApplication               : Started application in 0.433 seconds (JVM running for 24.348)
2015-04-08 12:22:54.099  INFO 85076 --- [nio-8888-exec-2] o.s.c.c.s.NativeEnvironmentRepository    : Adding property source: file:/Users/sgibb/workspace/spring/spring-cloud-samples/configserver/target/config/foo.properties
2015-04-08 12:22:54.099  INFO 85076 --- [nio-8888-exec-2] o.s.c.c.s.NativeEnvironmentRepository    : Adding property source: file:/Users/sgibb/workspace/spring/spring-cloud-samples/configserver/target/config/application.yml
2015-04-08 12:22:54.099  INFO 85076 --- [nio-8888-exec-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@416d044c: startup date [Wed Apr 08 12:22:54 EDT 2015]; root of context hierarchy

这很正常。启动和停止的不是应用程序,它只是用于为远程客户端创建配置资源的微型上下文。完全无害。

我在这里发现了我面临的问题。基本上,我们在 AWS 上有两个远程服务 运行 和一个已配置的 Load Balanacer,它会持续检查 /health 端点。通过调用此方法,ConfigServerClient 始终调用我们的 ConfigServer。

我不明白为什么 ConfigServer 有一个 HealthIndicator,有没有办法禁用这个 HealthIndicator,因为对该端点的每个请求都会一次又一次地查询我们的配置服务器。另一个缺点是,/health 请求不再尽可能快地响应,这会导致负载均衡器超时(默认 2s)。