首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL启动后无法运行Spring引导服务,因为Spring数据库尚未就绪

MySQL启动后无法运行Spring引导服务,因为Spring数据库尚未就绪
EN

Stack Overflow用户
提问于 2016-09-21 20:54:05
回答 1查看 551关注 0票数 0

我已经在我的Ubuntu16服务器上安装了一个Spring Boot应用程序作为init.d服务,在系统启动时自动运行as described here

我也有MySQL数据库,我需要为春季启动应用程序。问题是,在Spring boot尝试连接到db之后,应用程序崩溃:

代码语言:javascript
复制
2016-09-21 12:54:32.382 ERROR 1384 --- [           main] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_101]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_101]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_101]
...
Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_101]
...
2016-09-21 12:54:32.384  WARN 1384 --- [           main] o.h.e.jdbc.internal.JdbcServicesImpl     : HHH000342: Could not obtain connection to query metadata : Communications link failure

我认为,这是因为MySQL数据库还没有准备好。但这会导致Spring Boot App完全失败。

当我再次尝试手动启动相同的服务时,一切都运行得很好。

所以,我的问题是,我能定义某种init.d依赖吗?所以我的Spring启动应用要等到数据库准备好了?

EN

回答 1

Stack Overflow用户

发布于 2016-09-21 21:05:57

我正在使用systemd。

在您的链接的part中:

代码语言:javascript
复制
[Unit]
Description=myapp
After=mysql.service

[Service]
User=myapp
ExecStart=/var/myapp/myapp.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

如我所示,更改After行,将syslog替换为mysql。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39617158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档