如何将Spring Boot(可执行jar)部署到Azure App Service

时间:2017-06-07 05:40:52

标签: azure spring-boot azure-pipelines azure-pipelines-release-pipeline

问题是目前Azure支持将WAR文件部署到Tomcat中。 Spring Boot确实支持通过WAR进行部署,但是这会抵消使用Spring Boot的一些好处。

2 个答案:

答案 0 :(得分:2)

第一个问题是您需要一种方法来向服务传达您要运行的内容。这可以通过将web.config添加到应用服务的site \ wwwroot文件夹来处理。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        <httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
        arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\@project.artifactId@-@project.version@.jar&quot;">
        </httpPlatform>
    </system.webServer>
</configuration>

要保持web.config不在src我更喜欢将它放在{project root} / wwwroot

之下

使用Maven,您可以添加以下内容并在包中动态包含项目/发布。

    <build>
        <resources>
            <resource>
                <directory>${project.basedir}/wwwroot</directory>
                <filtering>true</filtering>
                <targetPath>${basedir}/target</targetPath>
            </resource>
        </resources>
    </build> 

现在将jar文件和web.config放在Azure App Service中。

如果您使用的是VSTS,则需要3个任务

任务1:停止Azure应用程序

任务2:使用FTP或SSH将jarweb.config上传到App Service

任务3:启动App Service。

答案 1 :(得分:0)

在wwwroot文件夹下添加web.config,在web.config中提及你的jar名称。完成后,将所需的jar上传到同一文件夹。要通过FTP上传,您需要先在Azure中的AppService下的凭据刀片下设置凭据