Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.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 尝试访问类时的状态404_Java_Maven_Api_Spring Boot - Fatal编程技术网

Java 尝试访问类时的状态404

Java 尝试访问类时的状态404,java,maven,api,spring-boot,Java,Maven,Api,Spring Boot,我刚开始使用maven学习spring引导,并按照教程从以下链接创建RESTfull web服务:。当我运行应用程序并尝试使用postman进行测试时,结果是404找不到 运行应用程序: java -jar target/demo-0.0.1-SNAPSHOT.war 邮递员中的Url测试: http://localhost:8080/greeting 问候语控制器与教程中的相同 这是我的基本类: package com.example.demo; import org.springfra

我刚开始使用maven学习spring引导,并按照教程从以下链接创建RESTfull web服务:。当我运行应用程序并尝试使用postman进行测试时,结果是404找不到

运行应用程序:

java -jar target/demo-0.0.1-SNAPSHOT.war
邮递员中的Url测试:

http://localhost:8080/greeting
问候语控制器与教程中的相同

这是我的基本类:

package com.example.demo;

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

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemoApplication.class);
    }

    public static void main(String[] args){
        SpringApplication.run(DemoApplication.class, args);
    }
}
这是我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </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>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>             
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

4.0.0
com.example
演示
0.0.1-快照
战争
演示
SpringBoot的演示项目
org.springframework.boot
spring启动程序父级
2.1.0.1发布
1.8
org.springframework.boot
春靴起跑服
org.springframework.boot
弹簧起动试验
测试
com.jayway.jsonpath
json路径
测试
org.springframework.boot
弹簧启动机tomcat
假如
org.springframework.boot
springbootmaven插件
重新包装
春假
https://repo.spring.io/libs-release
春假
https://repo.spring.io/libs-release

由于pom与本教程中的pom不同,因此看起来您进行了更改

例如,您错过了下面的
spring boot starter web
dependency。因此,交叉验证本教程所需的所有dependency并添加

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

org.springframework.boot
SpringBootStarterWeb

尝试清除(删除)
.m2
存储库,然后再次执行
mvn clean install

由于pom与本教程中的pom不同,您似乎已进行了更改

例如,您错过了下面的
spring boot starter web
dependency。因此,交叉验证本教程所需的所有dependency并添加

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

org.springframework.boot
SpringBootStarterWeb

尝试清除(删除)
.m2
存储库,然后再次执行
mvn clean install

那么,为什么您认为您应该使用404以外的东西呢?你是否编写了一些映射到URL/问候语的服务?你是说你遵循了教程,但是pom已经与教程中的非常不同了,那么你到底想实现什么呢?确切地说,我忘了把它改为开头,谢谢@JBNizetSo,你为什么认为你应该有404以外的东西?您是否编写了一些映射到URL/问候语的服务?您是说您遵循了教程,但是pom已经与教程中的非常不同,那么您到底想实现什么?确切地说,我忘了将其更改为开头,谢谢@JBNizet