问题在于,目前 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 "%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"">
</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 将 jar
和 web.config
上传到应用服务
任务 3:启动应用服务。
关于azure - 如何将 Spring Boot(可执行 Jar)部署到 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44404363/