java - 从脚本启动 Spring boot 应用程序

标签 java spring spring-boot

使用普通的 spring mvn 命令,我可以从命令行启动 spring boot 应用程序并使用 Control+c 终止它。不过,我已经创建了一堆服务,稍后我将对其进行 dockerize。现在它们是由 mvn 生成的普通 java jar 文件。如何使用python脚本或Bash脚本将它们一一启动,然后使用脚本终止它们。有什么方法可以启动它并且脚本不会阻止并且应用程序将有一个我稍后可以用来停止应用程序的名称?

最佳答案

我会遵循 documentation将 Spring-Boot 应用程序安装为 Unix/Linux 服务。

您所要做的就是将此依赖项添加到您的 pom.xml 中:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>

添加插件后,您应该安装并创建一个指向您的应用程序的符号链接(symbolic link) ( exact part of documentation ):

Assuming that you have a Spring Boot application installed in /var/myapp, to install a Spring Boot application as an init.d service simply create a symlink:

$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp

Once installed, you can start and stop the service in the usual way. For example, on a Debian based system:

$ service myapp start

然后您就可以创建一个 bash 脚本来以干净的方式启动停止重新启动您的应用程序。

关于java - 从脚本启动 Spring boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41927377/

相关文章:

java - 如何使用 Map 应用 setText 方法,其中我的 JTextField 元素已在 Map 中分配?

spring - 将 SVN 添加到 Spring Tool Suite,Subclipse 扩展不可用

java - 更新字符串字段,将 mongodb 中的另一个字符串与 spring-data 连接起来

java - 如何使用maven更改tomcat服务器的端口号

java - JMX 的使用以及如何用于现有应用程序

java - 当某些条件不成立时中断文件上传

java - Spring Boot Web应用程序错误: No mapping found for HTTP request with URI [/] in DispatcherServlet with name 'dispatcherServlet'

java.net.SocketException : Connection reset in spring Rest template

java - Android N - 在运行时更改区域设置

spring - Apache Poi SAX 写入空单元格