Azure Web 应用程序返回 404 错误代码

问题描述 投票:0回答:1

我在 Azure 应用服务上部署了一个用 Kotlin 编写的 Spring Boot 应用程序,版本为 3.1.10。该应用程序已上线,它显示默认页面:“您的应用程序服务已启动并正在运行。是时候采取下一步并部署您的代码了。”我使用 Terraform 进行部署。

使用 CICD.yml 中使用的 .jar 文件部署 Spring Boot 应用程序会自动执行整个过程,但是当我尝试访问该服务时,它会显示 404 Not Found 错误。

运行时堆栈 Java 17 Tomcat

有人有想法吗?

我已经尝试过的解决方案。

  • ApplicationInsight_JAVA_EXTENSION = 3.4.10

(https://stackoverflow.com/1

这是我的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'
postgresql spring-boot azure azure-appservice
1个回答
0
投票
  • 检查控制器映射,确保您尝试访问的路径(应用程序 URL)与应用程序中的映射匹配。
  • 验证应用程序正在侦听正确的端口。您可以通过在
    WEBSITES_PORT=<port_number>
    中添加设置
    Azure App Service=>Application Settings
    将应用程序配置为侦听所需端口。
  • 导航到应用服务的 KUDU 站点 (
    https://appname.scm.azurewebsites.net
    ),
    site/wwwroot
    并检查 jar 文件是否已部署且可用。

enter image description here

  • 在 Azure 应用服务的 KUDU 站点(https://appname.scm.azurewebsites.net/api/logstream)中检查应用程序的
    LogStream
    中的日志:

enter image description here


我使用 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!"
}
  • 使用 GitHub 操作部署到 Azure 应用服务。 GitHub 工作流程:
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'

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.