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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/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
基本spring rest api教程找不到404-';世界你好';_Spring_Spring Boot_Rest - Fatal编程技术网

基本spring rest api教程找不到404-';世界你好';

基本spring rest api教程找不到404-';世界你好';,spring,spring-boot,rest,Spring,Spring Boot,Rest,我正在尝试创建一个RESTAPI web应用程序,它最终可以部署到容器环境中。我也从spring.io下载了不少教程到其他网站,但每次使用精确的repos时,对于简单的请求,我都会收到404错误 为了进一步简化,我将其简化为一个包中的两个类: 主要类别: import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; i

我正在尝试创建一个RESTAPI web应用程序,它最终可以部署到容器环境中。我也从spring.io下载了不少教程到其他网站,但每次使用精确的repos时,对于简单的请求,我都会收到404错误

为了进一步简化,我将其简化为一个包中的两个类:

主要类别:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;


 @SpringBootApplication
 public class Main {

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

 }
控制器类:

@RestController
@RequestMapping("/")
public class RESTController {

private final AtomicLong counter = new AtomicLong();
private static final String template = "Hello, %s!";
/*
 * REST API Test Methods
 */


@RequestMapping( "/greeting" )
   public String greeting() {
      return "It's working...!";
}
当然,实际的要求是:

http://localhost:8080/test_rest_api/greeting

HTTP Status 404 – Not Found


Type Status Report

Message /test_rest_api/greeting

Description The origin server did not find a current representation for the target resource or is not 
willing to disclose that one exists.


Apache Tomcat/8.5.43
通过运行方式在服务器上运行的;如果选择Run as java application并选择springboot,则会发生以下错误:

    java.lang.IllegalArgumentException: Sources must not be empty at 
    org.springframework.util.Assert.notEmpty(Assert.java:467)

我终于明白了,这是一个愚蠢的错误。我添加了项目名称作为请求url域的一部分

http://localhost:8080/test_rest_api/greeting

vs

http://localhost:8080/greeting