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

模块包结构如下:


控制器类代码如下:

@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模板

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>
<dependency>    
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>

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

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,如:

@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()



  • 10
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值