我已经在我的Ubuntu16服务器上安装了一个Spring Boot应用程序作为init.d服务,在系统启动时自动运行as described here。
我也有MySQL数据库,我需要为春季启动应用程序。问题是,在Spring boot尝试连接到db之后,应用程序崩溃:
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启动应用要等到数据库准备好了?
发布于 2016-09-21 21:05:57
我正在使用systemd。
在您的链接的part中:
[Unit]
Description=myapp
After=mysql.service
[Service]
User=myapp
ExecStart=/var/myapp/myapp.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target如我所示,更改After行,将syslog替换为mysql。
https://stackoverflow.com/questions/39617158
复制相似问题