@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class})

springboot 項目啓動報錯如下,分析是pom.xml中引入了mongdb的依賴,此時你可能不需要連接數據庫,那麼有兩種解決方式:

1.在pom.xml中找到對應的依賴,去除掉

2.可以在啓動類上通過禁用指定的自動化配置來避免加載不必要的自動化配置,例如:

@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class})
2021-03-30 16:04:49.152  WARN 7864 --- [           main] io.undertow.websockets.jsr               : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2021-03-30 16:04:49.233  INFO 7864 --- [           main] io.undertow.servlet                      : Initializing Spring embedded WebApplicationContext
2021-03-30 16:04:49.233  INFO 7864 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4438 ms
2021-03-30 16:04:50.615  INFO 7864 --- [           main] c.a.c.s.SentinelWebAutoConfiguration     : [Sentinel Starter] register SentinelWebInterceptor with urlPatterns: [/**].
2021-03-30 16:04:52.210  INFO 7864 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2021-03-30 16:04:52.457  INFO 7864 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
2021-03-30 16:04:52.846  INFO 7864 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 22 endpoint(s) beneath base path '/actuator'
2021-03-30 16:04:53.682  WARN 7864 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2021-03-30 16:04:53.683  INFO 7864 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2021-03-30 16:04:53.693  WARN 7864 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2021-03-30 16:04:53.693  INFO 7864 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2021-03-30 16:04:53.974  INFO 7864 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-30 16:04:54.246  INFO 7864 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'Nacos-Watch-Task-Scheduler'
2021-03-30 16:04:56.743  INFO 7864 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@b42d1c8, org.springframework.security.web.context.SecurityContextPersistenceFilter@5b9ed77b, org.springframework.security.web.header.HeaderWriterFilter@30eed725, org.springframework.security.web.authentication.logout.LogoutFilter@555454c7, org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter@9751c9, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@4b4a3114, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@7955b4d4, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@73983f07, org.springframework.security.web.session.SessionManagementFilter@89017e5, org.springframework.security.web.access.ExceptionTranslationFilter@5fb392e, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@4a5dc126]
2021-03-30 16:04:57.073  INFO 7864 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2021-03-30 16:04:57.972  WARN 7864 --- [           main] s.o.SpringCloudSecurityAutoConfiguration : All Spring Cloud Security modules and starters are deprecated. They will be moved to individual projects in the next major release.
2021-03-30 16:04:58.277  INFO 7864 --- [           main] io.undertow                              : starting server: Undertow - 2.1.4.Final
2021-03-30 16:04:58.292  INFO 7864 --- [           main] org.xnio                                 : XNIO version 3.8.0.Final
2021-03-30 16:04:58.322  INFO 7864 --- [           main] org.xnio.nio                             : XNIO NIO Implementation Version 3.8.0.Final
2021-03-30 16:04:58.406  INFO 7864 --- [           main] org.jboss.threads                        : JBoss Threads version 3.1.0.Final
2021-03-30 16:04:58.513  INFO 7864 --- [           main] o.s.b.w.e.undertow.UndertowWebServer     : Undertow started on port(s) 6062 (http)
2021-03-30 16:04:58.525  INFO 7864 --- [           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, DEFAULT_GROUP qn-report-biz 10.130.14.6:6062 register finished
2021-03-30 16:04:59.155  INFO 7864 --- [localhost:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server localhost:27017

com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
	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.PlainSocketImpl.connect(PlainSocketImpl.java:172)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
	at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
	... 3 common frames omitted

2021-03-30 16:04:59.803  INFO 7864 --- [           main] com.channelsoft.qn.report.App            : Started App in 18.809 seconds (JVM running for 21.935)

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章