Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Springboot应用程序中出现意外的白标签错误404_Java_Spring_Spring Boot - Fatal编程技术网

Java Springboot应用程序中出现意外的白标签错误404

Java Springboot应用程序中出现意外的白标签错误404,java,spring,spring-boot,Java,Spring,Spring Boot,我制作了一个简单的Spring启动应用程序,但由于某些原因,当我尝试访问它时,我总是得到一个404。它以前是有效的,我不知道是什么改变了。。 这是我的控制器方法: @RequestMapping("/countries/{country_name}") public ModelAndView returnCountry(@PathVariable("country_name") String name) { try {

我制作了一个简单的Spring启动应用程序,但由于某些原因,当我尝试访问它时,我总是得到一个404。它以前是有效的,我不知道是什么改变了。。 这是我的控制器方法:

@RequestMapping("/countries/{country_name}")
    public ModelAndView returnCountry(@PathVariable("country_name") String name) {
        try {
            JSONObject response = JsonReader.readJsonFromUrl("https://covid2019-api.herokuapp.com/v2/country/" + name);
            JSONObject data = (JSONObject) response.get("data");
            Country country = new Country(name, data.getInt("confirmed"), data.getInt("deaths"), data.getInt("recovered"), data.getInt("active"));
            return country;
        } catch (JSONException exception) {
            return new CovidExceptions("API error");
        } catch (NullPointerException exception) {
            return new CovidExceptions("Country not found! Use English country code");
        } catch (IOException exception) {
            return new CovidExceptions("Could not read from the API");
        }
    }
我认为这是一个错误:

o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
我试着把乡村班搬到其他目的地,但没有一个成功

还有我的pom:

<?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.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>de.fh.albsig</groupId>
    <artifactId>CovidTracker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>CovidTracker</name>
    <description>Tracker for Covid-19 cases</description>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20190722</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.10</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.quarkus/quarkus-junit5 -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <version>1.4.2.Final</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.10.19</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-checkstyle-plugin -->
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.1.1</version>
        </dependency>

<!--        &lt;!&ndash; https://mvnrepository.com/artifact/com.google.code.findbugs/findbugs &ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>com.google.code.findbugs</groupId>-->
<!--            <artifactId>findbugs</artifactId>-->
<!--            <version>3.0.1</version>-->
<!--        </dependency>-->


    </dependencies>

    <reporting>
        <plugins>
            <plugin>
                <groupId>com.google.code.findbugs</groupId>
                <artifactId>findbugs</artifactId>
                <version>3.0.1</version>
            </plugin>
        </plugins>
    </reporting>

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

<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-checkstyle-plugin</artifactId>-->
<!--                <version>3.1.1</version>-->
<!--                <configuration>-->
<!--                    <encoding>UTF-8</encoding>-->
<!--                    <consoleOutput>true</consoleOutput>-->
<!--                    <failsOnError>false</failsOnError>-->
<!--                    <linkXRef>false</linkXRef>-->
<!--                </configuration>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <id>validate</id>-->
<!--                        <phase>validate</phase>-->
<!--                        <goals>-->
<!--                            <goal>check</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--            </plugin>-->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.13.0</version>
                <executions>
                    <execution>
                    <id>validate</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    </execution>
                </executions>

            </plugin>

        </plugins>
    </build>


</project>


4.0.0
org.springframework.boot

因此,master上的代码可以工作,而在测试分支上显示404错误。我比较了代码,但似乎无法找出错误所在。

您的方法返回类型是ModelAndView,您正在从方法内部返回country对象。您的MasterBranch控制器具有正确的代码。

是,因为我不想根据具体情况发送国家/地区对象或错误对象。。Country是ModelAndView的继承者,所以我认为这会起作用?仅当您希望在Jsp之类的视图中显示响应时,在这种情况下,使用ModelAndView作为返回对象。。。