changgongzhao的专栏

于大千识界,自见成长

浏览器请求spring-boot模块项目报:There was an unexpected error (type=Not Found, status=404).

转自 https://blog.csdn.net/zht741322694/article/details/79688728
模块包结构如下:
这里写图片描述
控制器类代码如下:

[java] view plain copy
@RestController
@RequestMapping(“/dispatchCenter”)
public class DispatchCenterController {

private static final Logger LOGGER = LoggerFactory.getLogger(DispatchCenterController.class);  

@RequestMapping(value = "/doMain",method = RequestMethod.GET)  
public String dispatchCenter(@RequestParam(value = "seqNo") String seqNo){  

    System.out.print(seqNo);  

    return "hello spring-boot";  
}  

}
在浏览器中输入http://localhost:7071/dispatchCenter/doMain?seqNo=%22hello%22报如下错误:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Mar 25 17:38:52 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available
1、首先查看在pom中配置或者是有没有正确加载,以及你是否使用了thymeleaf模板

[html] view plain copy

[html] view plain copy

org.springframework.boot
spring-boot-starter-parent
1.4.2.RELEASE


org.springframework.boot
spring-boot-starter-web

org.springframework.boot spring-boot-starter-thymeleaf
2、在浏览器中输入的URL是否正确,spring-boot项目是不需要跟spring项目一样还要带上项目名称

[plain] view plain copy
http://localhost:7073/rabbitMq/helloQueue2
3、Application启动类文件的包必须是项目下的父路径,其他类的包路径必须是其子路径,虽然放在其它包下也能正常启动,但是就是在浏览器中访问不到,因为handleMapper扫描不到,可以在启动类上加上注解

@ComponentScan(basePackages = {“com.spring.*”})
4、最后我的原因是第三点所描述的问题,于是将DispatchCenterApplication.java移动到com.dispatchCenter包下,启动后成功解决问题。

5、如果不是以上问题,就去查看spring-boot项目的启动日志,看看o.s.w.s.m.m.a.RequestMappingHandlerMapping中有没有你所配置的handelMapping,如:

[java] view plain copy
@RestController
@RequestMapping(“/rabbitMq”)
public class HelloRabbitMQController {
@Autowired
private AmqpTemplate amqpTemplate;

/**实现消息的发送*/  
@RequestMapping(value = "/helloQueue",method = RequestMethod.GET)  
public void send(){  
    String message = "this is queue test!";  
    this.amqpTemplate.convertAndSend("hello-queue",message);  
}  
@RequestMapping(value = "/helloQueue2",method = RequestMethod.GET)  
public void send2(){  

}  

}
日志中应该会如下信息说明就成功扫描到并注册了handelMapping,如果没有就仔细检查路径的配置,还有就是@RequestMapping(value=”*”) 这个value是不是写成name了

2018-04-05 17:06:39.059 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped “{[/rabbitMq/helloQueue],methods=[GET]}” onto public void com.dataService.controller.HelloRabbitMQController.send()
2018-04-05 17:06:39.059 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped “{[/rabbitMq/helloQueue2],methods=[GET]}” onto public void com.dataService.controller.HelloRabbitMQController.send2()

阅读更多
个人分类: java
上一篇char可以存储汉字吗?为什么
下一篇恢复ORACLE被误更新或删除数据的方法
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭