> 文档中心 > SpringBoot项目启动就停止,数据源启动就关闭、多数据源配置问题

SpringBoot项目启动就停止,数据源启动就关闭、多数据源配置问题

SpringBoot项目启动就停止,数据源启动就关闭、多数据源配置问题

  • 1. 数据源启动就关闭 INFO com.alibaba.druid.pool.DruidDataSource- {dataSource-1} closed
  • 多数据源未指定@Primary的问题
    • 解决方案:
    • 日志详情:

最近在跑一个项目的时候碰到了一些问题。所以来记录一下解决方案。

1. 数据源启动就关闭 INFO com.alibaba.druid.pool.DruidDataSource- {dataSource-1} closed

解决方案:

修改 build.gradle 配置文件

//    runtime("org.apache.tomcat.embed:tomcat-embed-jasper")    compile("org.apache.tomcat.embed:tomcat-embed-jasper")

注意:这里还有一个原因,可能是由于配置文件中某一个配置缺失导致的。

日志详情:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2022/04/29-11:47:20 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter- *APPLICATION FAILED TO START*2022/04/29-11:47:20 [main] INFO  org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext- Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@5491f68b: startup date [Fri Apr 29 11:45:47 CST 2022]; root of context hierarchy2022/04/29-11:47:20 [main] INFO  org.springframework.context.support.DefaultLifecycleProcessor- Stopping beans in phase 21474836472022/04/29-11:47:20 [main] INFO  org.springframework.context.support.DefaultLifecycleProcessor- Stopping beans in phase 202022/04/29-11:47:20 [main] INFO  org.springframework.jmx.export.annotation.AnnotationMBeanExporter- Unregistering JMX-exposed beans on shutdown2022/04/29-11:47:20 [main] INFO  org.springframework.jmx.export.annotation.AnnotationMBeanExporter- Unregistering JMX-exposed beans2022/04/29-11:47:20 [main] INFO  org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor- Shutting down ExecutorService 'asyncServiceExecutor'2022/04/29-11:47:20 [main] DEBUG com.augurit.agcloud.opus.common.sc.scc.runtime.kernal.engine.OpusSccCommandFactory- 清除SpringContextHolder中的ApplicationContext:org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@5491f68b: startup date [Fri Apr 29 11:45:47 CST 2022]; root of context hierarchy2022/04/29-11:47:20 [main] INFO  com.augurit.agcloud.bpm.common.timeCalculate.timer.TimeCalculateTimerShutdown- ----------系统关闭,关闭定时器线程池--------2022/04/29-11:47:20 [main] INFO  org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler- Shutting down ExecutorService2022/04/29-11:47:20 [main] INFO  org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor- Shutting down ExecutorService 'downloadExecutor'2022/04/29-11:47:20 [main] INFO  org.flowable.job.service.impl.asyncexecutor.AbstractAsyncExecutor- Shutting down the async job executor [org.flowable.spring.job.service.SpringAsyncExecutor].2022/04/29-11:47:20 [flowable-reset-expired-jobs] INFO  org.flowable.job.service.impl.asyncexecutor.ResetExpiredJobsRunnable- stopped resetting expired jobs2022/04/29-11:47:20 [flowable-acquire-timer-jobs] INFO  org.flowable.job.service.impl.asyncexecutor.AcquireTimerJobsRunnable- stopped async job due acquisition2022/04/29-11:47:20 [flowable-acquire-async-jobs] INFO  org.flowable.job.service.impl.asyncexecutor.AcquireAsyncJobsDueRunnable- stopped async job due acquisition2022/04/29-11:47:20 [main] INFO  org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor- Shutting down ExecutorService 'dataExchangeThreadPool'2022/04/29-11:47:20 [main] INFO  com.alibaba.druid.pool.DruidDataSource- {dataSource-1} closedDisconnected from the target VM, address: '127.0.0.1:63538', transport: 'socket'Process finished with exit code 1

多数据源未指定@Primary的问题

简述1:required a single bean, but 2 were found
简述2:At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
要求一个单独的bean

解决方案:

@Configurationpublic class DruidConfig {    @Primary//选择一个数据源,加上@Primary注解    @ConfigurationProperties(prefix = "spring.datasource")    @Bean(initMethod = "init", destroyMethod = "close")    public DruidDataSource druidDataSource() { DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setProxyFilters(Lists.newArrayList(statFilter())); return druidDataSource;    }    // 此处省略后面的配置}

日志详情:

SpringBoot启动Logo2022/04/29-16:02:33 [main] INFO  org.springframework.data.repository.config.RepositoryConfigurationDelegate- Multiple Spring Data modules found, entering strict repository configuration mode!2022/04/29-16:02:34 [main] INFO  org.springframework.data.repository.config.RepositoryConfigurationDelegate- Multiple Spring Data modules found, entering strict repository configuration mode!2022/04/29-16:02:41 [main] INFO  org.apache.coyote.http11.Http11NioProtocol- Initializing ProtocolHandler ["http-nio-8083"]2022/04/29-16:02:41 [main] INFO  org.apache.catalina.core.StandardService- Starting service [Tomcat]2022/04/29-16:02:41 [main] INFO  org.apache.catalina.core.StandardEngine- Starting Servlet Engine: Apache Tomcat/8.5.312022/04/29-16:02:41 [localhost-startStop-1] INFO  org.apache.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: [此处省略]这里省略一堆文件找不到,但不影响运行的log2022/04/29-16:02:42 [localhost-startStop-1] INFO  org.apache.jasper.servlet.TldScanner- At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.2022/04/29-16:02:42 [localhost-startStop-1] INFO  org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/aplanmis-front]- Initializing Spring embedded WebApplicationContext2022/04/29-16:02:46 [main] INFO  org.apache.catalina.core.StandardService- Stopping service [Tomcat]Disconnected from the target VM, address: '127.0.0.1:65277', transport: 'socket'Process finished with exit code 1

参考:【多数据源配置时出现的一些问题】
https://blog.csdn.net/weixin_42074377/article/details/83615895

SpringBoot项目启动就停止,数据源启动就关闭、多数据源配置问题 创作打卡挑战赛 SpringBoot项目启动就停止,数据源启动就关闭、多数据源配置问题 赢取流量/现金/CSDN周边激励大奖美国云服务器