I'm getting error 404 while trying to access my spring boot app on Amazon Elastic Bean Stalk

前端 未结 4 2087
北荒
北荒 2021-01-17 14:51

I developed a spring boot application and I\'ve put the following entries in src/main/resources/application.properties:

spring.mvc.         


        
相关标签:
4条回答
  • 2021-01-17 15:32

    Since you have your app on port 5000 it is accessible on that port, not default http port 80.

    Either access it with

    http://my-aws-ebs-instance.com:5000/welcome
    

    or create port forwarding rune in AWS so traffing going to port 80 will be pushed you application server's port 5000.

    0 讨论(0)
  • 2021-01-17 15:35

    If you check the Spring Boot docs, its clear that you are using the wrong directory structure.

    https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc

    By default, Spring Boot serves static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext ... Do not use the src/main/webapp directory if your application is packaged as a jar. Although this directory is a common standard, it works only with war packaging, and it is silently ignored by most build tools if you generate a jar.

    0 讨论(0)
  • 2021-01-17 15:41

    Nice explanation @dipak-thoke.

    Just to add if anyone automating the deployment process (In my case, it was through CodeBuild And CodeDeploy), you can create Procfile and deploy the war. I have added Procfile into the root directory of the project and added it as an artifact. Hope this helps someone looking for same usage case :)

    ProcFile:

    web: java -jar <your_war_file>.war 
    

    This is how my CodeBuild Buildspec looks like:

    version: 0.2
    
    phases:
    
      build:
        commands:
          # - command
          - ./gradlew bootWar
      post_build:
        commands:
          # - command
          - echo Build must be completed
          - mv build/libs/*.war <WarFileName>.war
    
    artifacts:
      files:
        # - location
         - <WarFileName>.war
         - Procfile
      #name: $(date +%Y-%m-%d)
      #discard-paths: yes
      #base-directory: location
    #cache:
      #paths:
        # - paths
    
    0 讨论(0)
  • 2021-01-17 15:42

    Solution 1:

    If you want Spring Boot With JSPs in Executable Jars

    Keep in mind that we will ultimately place the JSP templates under src/main/resources/META-INF/resources/WEB-INF/jsp/

    Note : define the template prefix and suffix for our JSP files in application.properties

    spring.mvc.view.prefix=/WEB-INF/jsp/
    spring.mvc.view.suffix=.jsp
    

    Then your can run jar file using below command :

    java -jar <your jar name>
    
     for your project you can below command
    
       java -jar  auth-1.3.5.RELEASE.jar
    

    For More reference : https://dzone.com/articles/spring-boot-with-jsps-in-executable-jars-1

    Solution 2:

    JSP Limitations

    When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.

    With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar. Undertow does not support JSPs. Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.

    I have clone your GitHub project able to run project(if you follow below steps your problem will get solve definitely)

    Step To run your project :
    
    Step 1 : Create war package of your project
    
    Step 2 : Run your war package using below command 
    
        java -jar <your war file name> 
    
        i.e for your project command should be like :
    
          java -jar  auth-1.3.5.RELEASE.war
    
    Step 3 : Hit the URL  http://localhost:5000/
    

    You can see the result in browser.

    More reference : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-jsp-limitations

    0 讨论(0)
提交回复
热议问题