springboot 创建web应用 编写helloworld访问404

@SpringBootApplication
public class SpringbootApplication {

    public static void main(String[] args) {
    	SpringApplication.run(SpringbootApplication.class, args);
    }
}
@RestController
public class TestController {

	@GetMapping("/hello")
	public String hello() {
		return "hello world";
	}
	@GetMapping("/")
	public String a() {
		System.out.println("进入a方法了");
		return "this is new method";
	}
}

访问的时候出现404,百度了才知道


两个类必须在一个包中controller才能被注册到springboot中


<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
    <relativePath /> 
</parent>

不知道为什么,1.5.6的版本 @SpringBootApplication 注解报错,后来换成2.0.3的版本就没事了。

猜你喜欢

转载自blog.csdn.net/weixin_39144798/article/details/80944910