springBoot啟動后 http://localhost:8080 地址無法訪問


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM