“ERROR“ dispatch for GET “/error“ 错误解决

本文介绍了一个Spring MVC项目中出现的404错误案例,通过调整@ComponentScan注解的配置解决了问题。

背景描述

写了一个demo接口,使用postman请求时报错。

@RequestMapping("/hello")
    public String helloworld(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String format = sdf.format(new Date());
        return "Hello Qiu Yihang ! 现在的时间是:".concat(format);
    }

报错信息:

[2021-07-17 23:29:02] [http-nio-80-exec-5] DEBUG servlet.DispatcherServlet:1127: Exiting from "ERROR" dispatch, status 404
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG servlet.DispatcherServlet:91: GET "/test/hello", parameters={}
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG handler.SimpleUrlHandlerMapping:522: Mapped to ResourceHttpRequestHandler [Classpath [META-INF/resources/], Classpath [resources/], Classpath [static/], Classpath [public/], ServletContext [/]]
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG support.OpenEntityManagerInViewInterceptor:86: Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG resource.ResourceHttpRequestHandler:525: Resource not found
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG support.OpenEntityManagerInViewInterceptor:111: Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG servlet.DispatcherServlet:1131: Completed 404 NOT_FOUND
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG servlet.DispatcherServlet:91: "ERROR" dispatch for GET "/error", parameters={}
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG annotation.RequestMappingHandlerMapping:522: Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG support.OpenEntityManagerInViewInterceptor:86: Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG view.ContentNegotiatingViewResolver:349: Selected 'text/html' given [text/html, text/html;q=0.8]
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG support.OpenEntityManagerInViewInterceptor:111: Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
[2021-07-17 23:29:37] [http-nio-80-exec-7] DEBUG servlet.DispatcherServlet:1127: Exiting from "ERROR" dispatch, status 404

解决:

把@ComponentScan注解去掉即可

@SpringBootApplication
@EnableJpaRepositories
@EnableCaching
//@ComponentScan(value = "ltd.hunter.justice.league.shopping.config")
public class JusticeLeagueShoppingApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(JusticeLeagueShoppingApplication.class, args);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new PerformanceInterceptor())
                .addPathPatterns("/coffee/**").addPathPatterns("/order/**");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值