How do I run a spring boot executable jar in a Production environment?

后端 未结 9 2107
一向
一向 2020-12-02 04:19

Spring boot\'s preferred deployment method is via a executable jar file which contains tomcat inside.

It is started with a simple java -jar myapp.jar.

9条回答
  •  有刺的猬
    2020-12-02 05:02

    Please note that since Spring Boot 1.3.0.M1, you are able to build fully executable jars using Maven and Gradle.

    For Maven, just include the following in your pom.xml:

    
        org.springframework.boot
        spring-boot-maven-plugin
        
            true
        
    
    

    For Gradle add the following snippet to your build.gradle:

    springBoot {
        executable = true
    }
    

    The fully executable jar contains an extra script at the front of the file, which allows you to just symlink your Spring Boot jar to init.d or use a systemd script.

    init.d example:

    $ln -s /var/yourapp/yourapp.jar /etc/init.d/yourapp
    

    This allows you to start, stop and restart your application like:

    $/etc/init.d/yourapp start|stop|restart
    

    Or use a systemd script:

    [Unit]
    Description=yourapp
    After=syslog.target
    
    [Service]
    ExecStart=/var/yourapp/yourapp.jar
    User=yourapp
    WorkingDirectory=/var/yourapp
    SuccessExitStatus=143
    
    [Install]
    WantedBy=multi-user.target
    

    More information at the following links:

    • Installation as an init.d service
    • Installation as a systemd service

提交回复
热议问题