springboot 在tomcat中启动两次

我开始以为眼花了,tomcat启动的时候,

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.2.RELEASE)

出现了两次,然后日志中有报错:

 Unable to register MBean [HikariDataSource (HikariPool-2)] with key 'dataSource ...

最终确认springboot被加载了两次。

原因一:

war包发布,可能没有排除内置tomcat,先确认exclusions

原因二:

tomcat的server.xml配置有问题

如果<Context>节点里配置了应用全路径,那么<host>节点里的appBase要置空,否则就是这出问题,host和context分别加载一次。

待测: 如果有两个springboot应用放在tomcat下的情况,还未测试。

猜你喜欢

转载自www.cnblogs.com/asker009/p/9763805.html