【问题标题】:Spring MVC Hello World app gives 404 errors on AWS elastic beanstalk, runs as expected locallySpring MVC Hello World 应用程序在 AWS 弹性 beantalk 上出现 404 错误,在本地按预期运行
【发布时间】:2020-02-10 11:54:24
【问题描述】:

该应用程序在我的 IDE(IntelliJ 社区版)中本地运行良好。我可以运行应用程序,在浏览器中输入localhost:8080,它会显示“Hello World”

在 AWS 上,我进入软件配置部分并添加了一个环境变量 SERVER_PORT 并将其设置为 8080。

当我被提示需要什么类型的 beanstalk 配置时,我相信我选择了 Tomcat。

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.lizardgizzards</groupId>
    <artifactId>langsite</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>langsite</name>
    <description>Demo project for Spring Boot</description>

    <packaging>war</packaging>

    <properties>
        <java.version>11</java.version>
        <start-class>com.lizardgizzards.langsite.LangsiteApplication</start-class>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我找到this answer 并按照那里的指示进行操作,所以现在我的主课如下所示:

package com.lizardgizzards.langsite;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class LangsiteApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(LangsiteApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(LangsiteApplication.class, args);
    }
}

我会粘贴日志,但超出了堆栈溢出的字符限制。我在日志输出中做了ctrl+f 并搜索了“错误”、“严重”和“致命”,但没有看到任何结果。

有一些警告,例如:

[Sun Oct 13 18:26:14.321734 2019] [ssl:warn] [pid 3396:tid 139962572781632] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]

OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=64m; support was removed in 8.0

[Sun Oct 13 18:41:58.389785 2019] [proxy:warn] [pid 4934:tid 140166163138304] [client 178.73.215.171:54277] AH01092: no HTTP 0.9 request (with no host line) on incoming request and preserve host set forcing hostname to be ip-172-31-18-139.us-west-1.compute.internal for uri /

13-Oct-2019 18:36:07.679 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]

在生成war文件时,我使用如下maven命令:mvn clean install spring-boot:repackage

【问题讨论】:

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


    【解决方案1】:

    有点荒谬......但这是解决问题的方法:

    我更改了 Java 版本以匹配 AWS 上的 Java 版本:

    <java.version>1.8</java.version>
    

    【讨论】:

      猜你喜欢
      • 2015-11-07
      • 2014-04-24
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2021-06-25
      相关资源
      最近更新 更多