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包;從而訪問成功;