【问题标题】:404 error when Running Jar [Spring Boot]运行 Jar [Spring Boot] 时出现 404 错误
【发布时间】:2016-12-28 19:00:06
【问题描述】:

我遇到了一个问题,不知道出了什么问题。

我有一个使用 spring boot 的多模块 maven 项目。 Layout of the project

我正在使用 STS,一切都很好。如果我运行应用程序,它会运行服务器,并且我的索引位于 localhost:8080。

但是,我想从中生成一个 jar。所以,我正在使用 mvn clean install。它在 /target 中生成一个 jar。 jar 中的布局很好,有源代码和source of the client。 然后,我用 java -jar myJar.jar 运行我的 jar。服务器运行正常,但是当我尝试访问该站点时,出现错误 404。它找不到视图。

错误:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Dec 28 19:45:52 CET 2016
There was an unexpected error (type=Not Found, status=404).
No message available

这是我的 web 和客户端模块的 pom.xml。

客户端 pom.xml

   <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>projet.si</groupId>
        <artifactId>projetsi</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </parent>

      <groupId>projet.si</groupId>
      <artifactId>ProjetSI_client</artifactId>
      <name>ProjetSI_client</name>
      <url>http://maven.apache.org</url>

      <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/webapp</directory>
            </resource>
            <resource>
                <directory>${project.build.directory}/dist</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <outputDirectory>${project.build.directory}/classes/</outputDirectory>
                </configuration>
            </plugin> 
      </plugins>

      </build>



      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>

    </project>

模块 web pom.xml :

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>projet.si</groupId>
        <artifactId>projetsi</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <groupId>projet.si</groupId>
    <artifactId>ProjetSI_web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>ProjetSI_web</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>projet.si</groupId>
            <artifactId>ProjetSI_business</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>projet.si</groupId>
            <artifactId>ProjetSI_client</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <configuration>
                            <outputDirectory>${project.build.directory}/dist/</outputDirectory>
                            <includeArtifactIds>ProjetSI_client</includeArtifactIds>
                            <includeGroupIds>projet</includeGroupIds>
                            <includes>**/*</includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我已经搜索了 stackoverflow,但没有找到任何东西:/

如果您需要更多详细信息或代码,请告诉我,我会编辑。

谢谢!

【问题讨论】:

  • 什么是“白标错误”?如果您的意思是 404,请使用该术语。
  • 我猜这是 Spring boot 的默认错误 404 页面。我已经编辑了谢谢:)
  • 对于 spring-boot-starter-tomcat 依赖删除 scope-provided 然后尝试。
  • 没有提供的范围没有变化:/

标签: java spring maven spring-boot jar


【解决方案1】:

请检查您从浏览器点击的网址是否附加了任何方法。 404 - 未找到,您尝试访问的资源或 url 不存在。您应该将控制器的方法映射到“/”或您要访问的任何 url。

【讨论】:

    猜你喜欢
    • 2017-08-26
    • 2023-01-28
    • 2021-05-04
    • 2016-08-20
    • 1970-01-01
    • 2016-12-08
    • 2015-04-18
    • 2021-11-02
    • 2021-01-13
    相关资源
    最近更新 更多