我在 Azure 应用服务上部署了一个用 Kotlin 编写的 Spring Boot 应用程序,版本为 3.1.10。该应用程序已上线,它显示默认页面:“您的应用程序服务已启动并正在运行。是时候采取下一步并部署您的代码了。”我使用 Terraform 进行部署。
使用 CICD.yml 中使用的 .jar 文件部署 Spring Boot 应用程序会自动执行整个过程,但是当我尝试访问该服务时,它会显示 404 Not Found 错误。
运行时堆栈 Java 17 Tomcat
有人有想法吗?
我已经尝试过的解决方案。
这是我的cicd.yml
name: hello
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build Project
run: mvn clean install -DskipTests
- name: Upload Artifact for Deplyoment Job
uses: actions/upload-artifact@v2
with:
name: microservice
path: ${{ github.workspace}}/target/*.jar
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download Artifacts from build Job
uses: actions/download-artifact@v2
with:
name: microservice
- name: Deploy Microservice to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: abc-01
publish-profile: ${{secrets.AZURE_PUBLISH_PROFILE}}
package: '*.jar'
WEBSITES_PORT=<port_number>
中添加设置 Azure App Service=>Application Settings
将应用程序配置为侦听所需端口。https://appname.scm.azurewebsites.net
),site/wwwroot
并检查 jar 文件是否已部署且可用。https://appname.scm.azurewebsites.net/api/logstream
)中检查应用程序的LogStream中的日志:
我使用 Getmapping“/hello”创建了一个 Spring Boot 应用程序 Kotlin(正如您在屏幕截图中提到的)。
代码片段:
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@RestController
class HelloController {
@GetMapping("/hello")
fun index(@RequestParam("name") name: String) = "Hello, $name!"
}
name: Build and deploy JAR app to Azure Web App - <app-name>
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java version
uses: actions/setup-java@v1
with:
java-version: '17'
- name: Build with Maven
run: mvn clean install
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: java-app
path: '${{ github.workspace }}/target/*.jar'
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: java-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: '<app-name>'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_DC23D1D6912C486A94D72B8949EFE9DE }}
package: '*.jar'
输出: