一:創建Azure Web App Service on Windows
1. 在“Create a resource"中選擇 "Web App"
2. 新建Resource Group並且為應用程序創建實例名
3. 選擇 "Runtime stack, Operating System", 創建 “Windows Plan", 其他保留默認設置
4. 點擊"Review and create" 按鈕,然后點擊"Create"按鈕來創建Azure Web App service.
5. 部署完后,回到 Web App Service主頁,可以點擊URL查詢自己App Service.
6. 點擊你的Web App Service URL, 一下信息證明你的Web App service創建成功!
二:部署Spring Boot項目到Azure Web App Service
1. 安裝Git, Maven, Java8, 詳細步驟不在羅列。
2. 在本地克隆”Spring Boot Getting Start" sample project
git clone https://github.com/spring-guides/gs-spring-boot
3. 進入“complete" 目錄結構
cd gs-spring-boot/complete
4. 用Maven構建Jar包
mvn clean package
5. 用Maven在本地啟動Web App
mvn spring-boot:run
6. 在瀏覽器中測試Web App
http://localhost:8080
出現"Greetings from Spring Boot!",證明 Spring Boot項目在本地構建成功!
7. 下載並且解壓FTP工具FileZilla
8. 打開FileZilla程序,配置Host, UserName, Password
找到第一部分創建好的Azure Web App, 到"Deployment Center"頁面,選擇"FTP"
點擊"Dashboard"頁面,復制FTPS Endpoint 值到FileZilla的Host,復制Username跟Password值分別到FileZilla的Username 和 Password。
將Host, Username, Password信息輸入好之后,點擊"Quickconnect",在彈出的對話框中選擇Ok接受認證,這樣就本地成功連接到Azure上的Web App service。
9. 上傳Spring Boot Jar包跟web.config到Azure web app service上
上傳Maven構建好的Jar包到 Azure web app上的folder "webapps".
上傳web.config文件到Azure web app上的 "wwwroot" 文件夾下
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 "%HOME%\site\wwwroot\webapps\gs-spring-boot-0.1.0.jar""> </httpPlatform> </system.webServer> </configuration>
10. 驗證Spring Boot代碼部署
登陸到Azure web app service主界面,點擊URL Link
至此,第一個Spring Boot項目成功在Azure Web App Service上部署成功!