【问题标题】:Spring Boot unable to find jsp files on ElasticBeanstalk AWSSpring Boot 无法在 ElasticBeanstalk AWS 上找到 jsp 文件
【发布时间】:2017-06-06 18:28:21
【问题描述】:

当应用程序从 Eclipse 运行时效果很好。但是问题是在我将应用程序打包到 JAR 或 WAR 并运行它之后开始的。 在每一页上获得 404。 这是我到目前为止所做的:

这是我的 POM 文件:

<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springtry</groupId>
<artifactId>spring</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring Maven Webapp</name>
<url>http://maven.apache.org</url>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>




<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-solr</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <!-- JSTL for JSP -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
         <scope>provided</scope>
    </dependency>

    <!-- Need this to compile JSP -->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Need this to compile JSP, tomcat-embed-jasper version is not working, 
        no idea why -->
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>4.6.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>3.5.0</version>
    </dependency>
     <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.10</version>
    </dependency>
</dependencies>
 <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>



    </plugins>
</build>

【问题讨论】:

  • 你能给我看看你的 pom.xml 吗?
  • @GippleLake 我已经添加了 pom。谢谢
  • 一切正常,除了“jar”。你必须打包去打仗
  • 我也尝试过打包到WAR。仍然可以获取 jsp 文件 :( Getting 404
  • 我不知道你为什么在资源目录中找到jsp文件。但是,如果您将其放入 webapp 中,它就可以正常工作。我是从javabycode.com/spring-framework-tutorial/spring-boot-tutorial/… 找到的

标签: spring jsp amazon-elastic-beanstalk


【解决方案1】:

所以为了解决这个问题,我将弹性 beanstalk 从 Java 更改为 Tomcat。现在它适用于 WAR。 使用 Java 我无法运行 webapp

【讨论】:

  • 当你使用 WAR 文件时,这绝对是一种方式。
  • 这解决了我一直面临的问题,我使用 Java 作为环境而不是 TomCat。
  • 修复了我的问题!伟大的 !。谢谢
  • 这解决了我的问题。我在这上面花了太多时间!!
【解决方案2】:

对于jar打包,jsp文件应该在src/main/resources/META-INF/resources/。 对于战争包装 src/main/webapp/ 是好的。 另外,我猜想通过战争包装,您可能没有在配置主类中使用它的方法 configure(...) 来实现 SpringBootServletInitializer。 一个完整的例子是here

【讨论】:

  • 所以我看到这两个选项都在我的本地机器上工作。但是在亚马逊上部署到弹性豆茎后我仍然遇到问题。谢谢!
猜你喜欢
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 2016-05-08
  • 1970-01-01
  • 2016-02-18
  • 2021-03-29
  • 2018-01-22
  • 2020-05-30
相关资源
最近更新 更多