springboot hikari连接不释放_SpringBoot自动化配置中碰到的问题

6944a9cd0a9be6056c61f34bac501d3d.png

Springboot的自动化配置给我们的开发提供了很大的便利,但是配置不当,可能引入了一些实际我们不需要的依赖,导致应用无法启动等等问题,如下面这个启动信息:

 . ____ _ __ _ _ / / ___'_ __ _ _(_)_ __ __ _    ( ( )___ | '_ | '_| | '_ / _` |     / ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.1.3.RELEASE)2019-03-14 21:02:05.007 INFO 5528 --- [ main] com.gwssi.Debug.DebugApplication : Starting DebugApplication on LAPTOP-VHUC0OI9 with PID 5528 (C:workspaceDebugDebugargetclasses started by Mundo in C:workspaceDebugDebug)2019-03-14 21:02:05.012 INFO 5528 --- [ main] com.gwssi.Debug.DebugApplication : No active profile set, falling back to default profiles: default2019-03-14 21:02:05.634 WARN 5528 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.gwssi.Debug]' package. Please check your configuration.2019-03-14 21:02:06.593 INFO 5528 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)2019-03-14 21:02:06.619 INFO 5528 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]2019-03-14 21:02:06.619 INFO 5528 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]2019-03-14 21:02:06.633 INFO 5528 --- [ 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: [C:Program FilesJavajdk1.8.0_66bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:ProgramDataOracleJavajavapath;C:Program Files (x86)InteliCLS Client;C:Program FilesInteliCLS Client;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program FilesJavajdk1.8.0_66bin;C:Program FilesJavajdk1.8.0_66jrebin;C:installapache-maven-3.5.4-binapache-maven-3.5.4bin;C:Program Filesodejs;C:Program FilesTortoiseSVNbin;C:installMicrosoft VS Codebin;C:WINDOWSSystem32OpenSSH;C:Program Files (x86)Bitvise SSH Client;C:Program FilesRedis;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:甥敳獲lenovoAppDataLocalMicrosoftWindowsApps;C:installodejsode_global;;C:installMicrosoft VS Codebin;.]2019-03-14 21:02:06.747 INFO 5528 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext2019-03-14 21:02:06.747 INFO 5528 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1671 ms2019-03-14 21:02:06.983 INFO 5528 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'2019-03-14 21:02:07.110 WARN 5528 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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 class2019-03-14 21:02:07.110 INFO 5528 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'2019-03-14 21:02:07.113 INFO 5528 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]2019-03-14 21:02:07.128 INFO 5528 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2019-03-14 21:02:07.133 ERROR 5528 --- [ main] o.s.b.d.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 classAction: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 (no profiles are currently active).
6d03a32a9c746cbdb8f7c12e32ce2749.png
Reason: Failed to determine a suitable driver class

从报错信息中,我们就可以分析出错误原因是触发了数据源的自动化配置,然而当前项目其实并不需要数据源。查其根源是依赖方提供的API依赖中引用了一些多余的依赖触发了该自动化配置的加载。

03267ae5d5b2018971f02f7ffea1a1c7.png

那得去掉这些不必要的配置,

一种方法:@SpringBootApplication提供了相应的注解参数支持

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

还可以通过在application.properties中加入下面配置,解决这个问题

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
d479eaf5b2b5a56063698e950eb2768f.png

Let's study Spring in spring

春天里学习Spring,很合时宜啊~~~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值