Search code examples
javaspring-bootazuregithub-actionscicd

REST API Spring 3.2.0 successfully deployed on azure but 404 error on endpoint


I'm trying to build a cicd pipeline and have made a spring (3.2.0) project (Java 17, gradle) on a simple rest api. At the moment, my pipeline is being built, tested and deployed on azure. All stages are successful, but when I'm on azure and try to reach my endpoint which is "{mywebsite}.azurewebsites.net**/api/students** it shows me a 404 error. To be more precise, my jar file is "server.jar" and is located in the "build/libs/server.jar" folder.

When I run my project locally, it works perfectly, but when it's on azure, it doesn't, as I get the 404 error. I've tried to resolve my error by modifying : ApplicationInsightsAgent_EXTENSION_VERSION : didn't work modify my .yml if it was my jar file after all: didn't work

Also, I went to .scm but when I go to files, I only get files of the type : ASP.NET or DeploymentLogStream. I figured out that these were just environment files and had nothing to do with my project. Now I don't know what to do because all the topics show the things I did previously. Did anybody had this issue ?

Just in case here is my deploy.yml file:

name: Build and deploy JAR app to Azure Web App 


on:
  push:
    branches:
      - dev
  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 Gradle
        run: ./gradlew build

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
        with:
          name: build
          path: build/libs/server.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: build
              path: build/libs/
          - name: show files
            run: ls -la
    
          - name: Deploy to Azure Web App
            id: deploy-to-webapp
            uses: azure/webapps-deploy@v2
            with:
              app-name: 'DevOpsProjectEfrei'
              slot-name: 'Production'
              publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_1BD6BC13408746048A3DDF66BE34382E }}
              package: 'build/libs/server.jar'
              

I've tried to resolve my error by modifying : ApplicationInsightsAgent_EXTENSION_VERSION : didn't work modify my .yml if it was my jar file after all: didn't work


Solution

  • I have deployed your spring boot project to Linux Azure App Service with JAVA 17 as Runtime Stack using GitHub actions:

    My GitHub workflow:

    name: Build and deploy JAR app to Azure Web App - springbootproject
    
    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 Gradle
            run: gradle build
    
          - name: Upload artifact for deployment job
            uses: actions/upload-artifact@v3
            with:
              name: build
              path: build/libs/server.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: build
                  path: build/libs/
              - name: show files
                run: ls -la
        
              - name: Deploy to Azure Web App
                id: deploy-to-webapp
                uses: azure/webapps-deploy@v2
                with:
                    app-name: 'springbootproject'
                    slot-name: 'Production'
                    package: '*.jar'
                    publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_ECA77XXXXXXXXXXXXX38CF0 }}
    

    Deployment Status in GitHub:

    enter image description here

    KUDU site of Web App(site/wwwroot):

    • Can see the Jar file of the project:

    enter image description here

    • Able to run the application with endpoint https://<webapp>.azurewebsites.net/api/students:

    enter image description here