azure - 如何将 Spring Boot(可执行 Jar)部署到 Azure 应用服务

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

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

最佳答案

第一个问题是您需要一种方法来与您尝试运行的服务进行通信。这可以通过将 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@<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="577a172725383d32342379213225243e3839" rel="noreferrer noopener nofollow">[email protected]</a>@.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 应用服务中。

如果您使用 VSTS,您将需要 3 个任务

任务 1:停止 Azure 应用程序

任务 2:通过 FTP 或 SSH 将 jarweb.config 上传到应用服务

任务 3:启动应用服务。

关于azure - 如何将 Spring Boot(可执行 Jar)部署到 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44404363/

相关文章:

Wildfly 中的 Spring Boot Websockets

ios - 在azure管道上的InstallAppleCertificate任务中从keyvault检索文件而不是安全文件

azure - 如何跟踪 Azure DevOps 上触发管道的原因?

python - 如何将 PySpark Dataframe 转换为 R 可以在 DataBricks 中识别的内容?

asp.net-mvc - Azure 混合连接与 Entity Framework 连接失败

java - 从 1.4.2 升级后,Spring Boot 1.4.3+ 中的 LoadTimeWeaving 不起作用

java - 如何使用第 3 方 @ConfigurationProperties @Bean?

continuous-integration - VSTS 发布管道找不到已发布的工件

Azure DevOps PowerShell - 我可以为库组变量构建变量字符串吗

azure - 可靠的参与者和取消 token