Spring bootプロジェクト起動自動ロードmongo構成失敗による起動失敗問題

9354 ワード

1回のspring bootプロジェクトの起動中に発生した問題をまとめると、起動時にdataSource defined in class path resource org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikariをロードするように提示することが主な原因である.classで失敗しました.
このプロジェクトはゲートウェイプロジェクトで、redisデータソースが1つしか構成されておらず、最近の構成は変更されていません(環境構成、pomは変更されています).だから突然起動に失敗して、困惑しています!テスト環境の問題(テスト環境で使用されているdockerは、安定していない)が疑われ始めた後、ローカルで起動し、予発環境でmasterブランチを起動し、docker環境要因を排除しました.
ログをよく見ると、dataSourceレポートのmongodb接続に失敗しました.つまりspring bootが起動時にdataSourceをロードし、プロファイルから接続mongodbをロードする構成が見つかりません.接続に失敗しました.
2020-04-10 09:47:47,567 [localhost-startStop-1] INFO  org.springframework.web.context.ContextLoader   - Root WebApplicationContext: initialization completed in 3576 ms
2020-04-10 09:47:48,107 [localhost-startStop-1] INFO  org.mongodb.driver.cluster   - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2020-04-10 09:47:48,129 [cluster-ClusterId{value='5e8fd0441919428f62237562', description='null'}-localhost:27017] INFO  org.mongodb.driver.cluster  com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.connection.SocketStream.open(SocketStream.java:62)
	at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:59)
	at com.mongodb.connection.SocketStream.open(SocketStream.java:57)
	... 3 common frames omitted
 - Exception in monitor thread while connecting to server localhost:27017
2020-04-10 09:47:48,396 [localhost-startStop-1] ERROR org.springframework.boot.web.embedded.tomcat.TomcatStarter   - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$ad1b39b4]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-04-10 09:47:48,410 [main] INFO  org.apache.catalina.core.StandardService   - Stopping service [Tomcat]

このプロジェクトはmongodb接続を構成する必要がないことが明らかになったので、mongodbのロードをブロックすることができます.具体的にはSpring bootでクラスアプリケーションの注釈@SpringBootAppliation(exclude={MongoAutoConfigure.class,MongoDataAutoConfigure.class})を起動し、再コンパイルして起動します.まだ失敗しています.しかし、問題の異常情報が変わりました.ログは次のとおりです.
2020-04-10 10:19:55,390 [localhost-startStop-1] ERROR org.springframework.boot.web.embedded.tomcat.TomcatStarter   - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$b3ab18de]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-04-10 10:19:55,406 [main] INFO  org.apache.catalina.core.StandardService   - Stopping service [Tomcat]
2020-04-10 10:19:55,415 [main] WARN  o.s.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext   - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2020-04-10 10:19:55,426 [main] INFO  o.s.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener   - 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-10 10:19:55,432 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter   - 

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

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).

今回はmongodb接続のロードに失敗したというメッセージはありませんが、dataSourceのロードに失敗したというメッセージが表示されます.つまり、dataSourceは起動時もロードされています.では、起動クラスにDataSourceAutoConfigurationを追加します.class、それから起動して、今度は正常です!
まとめ:プロジェクトの一部が外部に依存しているバージョンがSNAPSHOT版であるため、外部から不安定なバージョンが送信されず、プロジェクトの起動に失敗した.完全な構成は次のとおりです.
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class ,MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})