练习完springboot日志和定时器后的感悟和总结
springboot日志(调试去除system.out.println())
1、首先是确定日志类型slf4j、logback,…
2、其次确定相应的maven依赖
3、之后可以自己编写xml或直接在yml、properties文件中加入自己想要的日志类型
4、之后就可以通过注解使用日志
主要代码:
yml
logging.pattern.console=%d{yyyy-MM-dd} ----> [%thread] ----> %-5level---> %logger{50} ---> %msg%n
测试方法
Logger logger= LoggerFactory.getLogger(this.getClass());
@Test
public void contextLogger(){
this.logger.trace("这是trace");
this.logger.debug("这个debug日志...");
this.logger.info("这个info日志...");
this.logger.warn("这个warn日志...");
this.logger.error("这个error日志...");
}
截图:
定时器(发送文件,定时)
很简单,直接加注解就可以了
@EnableScheduling//开启定时器
@Scheduled() -->参数:fixedDelay、cron、fixedRate
之后启动就OK了
相关代码
@EnableScheduling//开启定时器
@SpringBootApplication
public class SpringbootloggingApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootloggingApplication.class, args);
}
//定时器
@Scheduled(fixedRate = 2000)
public void fixedRate() {
System.out.println("fixedRate>>>"+new Date());
}
@Scheduled(fixedDelay = 2000)
public void fixedDelay() {
System.out.println("fixedDelay>>>"+new Date());
}
@Scheduled(initialDelay = 2000,fixedDelay = 2000)
public void initialDelay() {
System.out.println("initialDelay>>>"+new Date());
}
}
感想:
一句话,springboot功能是真的强大和便捷。
至此,springboot学习之路告一段落,在这将近两个月的springboot学习时间里收获颇多,疫情期间一直在家自学,to be honest 在家学习氛围不是太好,总感觉效率很低。疫情嘛,每个人都是这样!
接下来我将会把重点放在spring、springmvc、mybatis这三大框架之上,继续完成未做完的项目,期间练习算法和面试题。