springboot注解:
@RefreshScope -- 配置文件自动刷新
@EnableScheduling -- 入口类加上此注解 @scheduled,在具体方法中加注解并设定定时时间fixedDelay 来执行定时任务
@EnableAutoConfiguration -- 开启自动配置功能@AutoConfigurationPackage -- 自动配置包
@Import({AutoConfigurationImportSelector.class}) -- 给容器中导入组件
@SpringBootApplication 将朱配置类的所在的包及下面所有的子类包里面所有的组件扫描到spring容器
@ControllerAdvice -- 注解可以静啊对于控制器的全局配置放在一个位置,作用在所用@RequestMapping的控制器方法上
@ExceptionHandler -- 用于全局处理控制器里的异常
用法:
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler({ArithmeticException.class})
@ResponseBody
public Map<String, Object> hadleArithmeticExcetion(ArithmeticException e){
Map<String, Object> map = new HashMap<String, Object>();
e.printStackTrace();
map.put("errorCode","201");
map.put("errorCode","算数异常");
return map;
}
@ExceptionHandler({Exception.class})
@ResponseBody
public Map<String, Object> hadleArithmeticExcetion(Exception e){
Map<String, Object> map = new HashMap<String, Object>();
e.printStackTrace();
map.put("errorCode","101");
map.put("errorCode","未知异常");
return map;
}
}
注意:本文归作者所有,未经作者允许,不得转载