http://localhpost:8080/hello
代码结构:
代码内容:
1 @RestController 2 public class HelloWordRestImpl implements HelloWordRest{ 3 4 @Autowired 5 public HelloWordService helloWordService; 6 7 @Override 8 @RequestMapping("/say") 9 public String say() { 10 return helloWordService.say(); 11 } 12 13 @Override 14 @RequestMapping("/hello") 15 public String hello() { 16 return "hello"; 17 } 18 }
解决方案:
1、首先查看自己配的controller路径是否和访问路径一致;
2、在确保springboot服务正常启动的情况,打开本地host,查看localhost的ip是否使用,一般情况是127.0.0.1,如果是注释的就放开;
3、如果你的springboot启动类和springbootController包是在不同的包里,就需要添加
@ComponentScan(basePackages = {"xx.xxx.*"}),后面是你的包路径
这样就能扫面到controller包;从而访问成功;