SpringBoot问题总结

1、This application has no explicit mapping for /error, so you are seeing this as a fallback.

  1. 入口类所在的位置不对,应位于所有子包的最外层
  2. 热部署时修改Controller时也会出现该问题,尝试将图中的配置移动到相对考下的位置,目前并未找到有效方法,这种情况只在本人项目中出现过

2、Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

入口类不能直接放在src/main/java目录下,必须在包内

3、springboot使用接口Validator实现自定义验证,在Controller中添加多个验证器时总会报错,可以以下方式加载多个验证器

@InitBinder
public void initBinder(WebDataBinder binder) {
if(loginValidate.supports(binder.getTarget().getClass()))
binder.addValidators(loginValidate);
else
binder.addValidators(consumeValidate);
}

在方法中如果有多个对象需要进行校验,则需要@Valid和BindingResult成对出现,如下图所示

@Valid Consume consume, BindingResult errors1, @Valid Login login, BindingResult errors2

posted @ 2017-07-28 09:56  YH_W  阅读(283)  评论(0编辑  收藏  举报