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