java - 将 Springboot 部署到 Azure 应用服务

标签 java azure web-applications spring-boot

我正在尝试将我的 springboot 项目部署到 Azure 应用服务中。 我创建了一个应用服务并通过 FTP 上传了两个文件:test.war 和 web.config,如教程中所述。

网络配置

<?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\test.war&quot;">
    </httpPlatform> 
  </system.webServer>
</configuration>

我将 war 文件上传到 site/wwwroot 并将 web.config 文件也放置在那里。

我的问题是:如何执行war文件?当我自动完成部署时应该发生这种情况吗?因为现在我得到的只是服务不可用,Http 错误 503。

谢谢

最佳答案

@ItaiSoudry,根据您web.config的内容文件中,似乎您想使用嵌入式 servlet 容器(如嵌入式 tomcat 或 jetty)来启动 spring boot web 应用程序。

假设您使用的IDE是Eclipse,您需要将您的Spring Boot项目导出为可运行的jar文件,而不是war文件,请参见下图。

enter image description here

enter image description here

注意:Launch configuration应选择main函数包含的ClassSpringApplication.run .

同时,您需要配置监听端口 %HTTP_PLATFORM_PORT%通过参数 --server.port=%HTTP_PLATFORM_PORT% 支持的 Azure 应用服务在 web.config文件或设置类的端口 ServerProperties 值为 System.getenv("HTTP_PLATFORM_PORT") .

这是 web.config 的示例与 --server.port=%HTTP_PLATFORM_PORT% .

<?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\test.jar&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

如果要部署war文件,需要配置ApplicationSettings在 Azure 门户上创建您的应用服务,然后将 war 文件上传到路径 wwwroot/webapps .

enter image description here

作为引用,请参阅以下文档。

  1. Springboot文章中的小节https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/#application-configuration-examples
  2. Create a Java web app in Azure App Service

希望有帮助。

关于java - 将 Springboot 部署到 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39103878/

相关文章:

java - 网络代理背后的 Spring-Boot

java - 为什么我的 Java 导入失败?

c# - 将消息定向给消费者

web-applications - 对 Web 应用程序执行压力测试?

tensorflow - 对如何在 Web 应用程序中使用一些基本的机器学习感到好奇

Java 8 List<Map<String, Object>> 到 List<Map<String, Object>> 按键分组并按值计数

java - 如何随意使用接口(interface)方法?

azure - 使用 Azure SDK v1.8 创建的 Blob 是页 Blob 还是 block Blob?

c# - 如何通过分区使用 CosmosDB 中的地理空间数据

html - 如何在 Firefox 中专门禁用 HTML5 应用程序缓存