将 Web 应用程序部署到 AWS Elastic beanstalk 后出现 404 错误

时间:2021-07-16 03:01:14

标签: java amazon-web-services spring-boot amazon-elastic-beanstalk

在将我的 AWS 应用程序部署到 Elastic beanstalk 后,我收到 404 错误

注意项目在本地运行良好

我认为问题是,它无法找到我的 html 文件(这就是它抛出 404 的原因)。

这些是我采取的步骤

  1. 我使用 Intellij 构建了一个 .JAR 工件(我认为这个过程中存在错误)。
  2. 然后我选择 Tomcat 作为我运行 Amazon Corretto 11 的环境。
  3. 然后我上传了我所说的 .JAR 文件

这就是我构建 .JAR 的方式

我在 Intellij 中单击了项目结构。这会打开这个窗口。 Window

然后我单击加号并从具有依赖项的模块中选择 JAR。这是开放的,这是我的选择。

Selection

最后这是它的样子,我相信它没有拿起我的资源文件夹,但是我不确定是否是这种情况

完成后我单击构建工件并将 .JAR 文件上传到 Amazon AWS Elastic BeanStalk What appears after JAR configuration is completed

但是一旦完成,我就会收到 404

  HTTP Status 404 – Not Found
Type Status Report

Message The requested resource [/] is not available

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.63

这是我的控制器

   @Controller
public class HomeController {




    @RequestMapping("/")
    public String index() throws IOException {
       return "home";
    }

    @RequestMapping("/search-country")
    public String login()
    {
        System.out.println("controller hit");
        return "Search";
    }

    @RequestMapping(value = "/home-page",method = RequestMethod.POST)
    public ModelAndView homepage(HttpServletRequest request) throws IOException {

        ApiCaller apiCaller = new ApiCaller(request.getParameter("country_text"));

        ModelAndView coronavirus = new ModelAndView("coronavirus");

        coronavirus.addObject("country_flag_url",apiCaller.getFlagURL());
        coronavirus.addObject("country_text","Cases for " + request.getParameter("country_text") + "as of " + Utils.todaysDate());
        coronavirus.addObject("total_cases_text","Cumulative Cases: " + Utils.addCommasToNumericString(apiCaller.getTotalCases()));
        coronavirus.addObject("deaths_today_text","Deaths today: " + Utils.addCommasToNumericString(apiCaller.getDeathsToday()));
        coronavirus.addObject("cases_today_text","Cases today: " + Utils.addCommasToNumericString(apiCaller.getCasesToday()));
        coronavirus.addObject("in_critical_care_text","In Intensive Care:" + Utils.addCommasToNumericString(apiCaller.getInCriticalCare()));
        coronavirus.addObject("population_text","Total Population: " +Utils.addCommasToNumericString(apiCaller.getInCriticalCare()));
        coronavirus.addObject("active_text","Active cases: " + Utils.addCommasToNumericString(apiCaller.getActiveCases()));
        coronavirus.addObject("recovered_text","Recovered Cases" + Utils.addCommasToNumericString(apiCaller.getRecovered()));
        coronavirus.addObject("deaths","Total deaths: " + Utils.addCommasToNumericString(apiCaller.getTotalCases()));




        return coronavirus;
    }

}

0 个答案:

没有答案