大家好,我是烤鸭:
今天分享一个springboot 闪退的问题。确切得说是没有起来。
环境:
springboot 版本 2.1.0.RELEASE
异常:
2019-05-25 19:39:00.822 ==> [main] ==> INFO com.cgmanage.migrate.MigrateApplication - Starting MigrateApplication v1.0.0-SNAPSHOT on localhost with PID 27493 (/opt/web_app/data_migrate/test-1.0.0.jar started by root in /opt/web_app/data_migrate)
2019-05-25 19:39:00.827 ==> [main] ==> DEBUG com.cgmanage.migrate.MigrateApplication - Running with Spring Boot v2.1.0.RELEASE, Spring v5.1.2.RELEASE
2019-05-25 19:39:00.830 ==> [main] ==> INFO com.cgmanage.migrate.MigrateApplication - No active profile set, falling back to default profiles: default
2019-05-25 19:39:04.153 ==> [main] ==> INFO org.apache.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8085"]
2019-05-25 19:39:04.172 ==> [main] ==> INFO org.apache.catalina.core.StandardService - Starting service [Tomcat]
2019-05-25 19:39:04.172 ==> [main] ==> INFO org.apache.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/9.0.12
2019-05-25 19:39:04.195 ==> [main] ==> 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: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2019-05-25 19:39:04.346 ==> [main] ==> INFO o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2019-05-25 19:39:04.620 ==> [main] ==> INFO org.apache.catalina.core.StandardService - Stopping service [Tomcat]
主要在于这两行:
No active profile set, falling back to default profiles: default
org.apache.catalina.core.StandardService - Stopping service [Tomcat]
解决方案:
网上说的是添加 springboot-web 的依赖,但是没用。
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
降低springboot 版本至 2.0.5.RELEASE ,还是不行。
同样的项目,测试环境可以跑起来,生产环境闪退,唯一的区别在于启动时指定的配置文件不同。
仔细对比配置文件,发现确实有个地方不一样。
测试环境的配置文件:
server:port: 8085
spring:application:name: test-migratedatasource:write:jdbc-url: jdbc:mysql://localhost:3306/test?useSSL=false&allowMultiQueries=true&useUnicode=true&characterEncoding=utf8username: rootpassword: rootdriver-class-name: com.mysql.jdbc.Drivertype: com.zaxxer.hikari.HikariDataSourceidleTimeout: 180000connectionTimeout: 180000validationTimeout: 6000maxPoolSize: 200minIdle: 100
生产的配置文件比测试少了一行。
idleTimeout: 180000
没错。就差这一行。
如果你也是跟我有一样的问题,日志打印也没报错的话。
建议检查一下配置文件,仔细对比一下。。。surprise