springboot搭建-学习摘要-02
1、异步方法和异步类
@Async 修饰方法,每次调用方法都会生成一个新线程
- SimpleAsyncTaskExecutor:简单的线程池,这个类不重用线程,每次调用都会创建一个新的线程。
- SyncTaskExecutor:这个类没实现异步调用,只是一个同步操作,只适合用于不需要多线程的地方。
- ConcurrentTaskExecutor:Executor的适配类,不推荐使用.。
- ThreadPoolTaskScheduler:可以和cron表达式使用。
- ThreadPoolTaskExecutor:最常用,推荐,其本质就是:java.util.concurrent.ThreadPoolExecutor的包装
附上参考文章地址 https://www.cnblogs.com/woniurunfast/p/14957012.html
2、springboot中集成Swagger
在一个方法上使用@Bean说明这个方法需要交给spring来进行管理
声明一个swaager配置类,用@EnableSwagger2注解注释,使用@Bean初始化一些相应的配置就行
参考 https://www.cnblogs.com/xuwujing/p/11042674.html 或者 https://www.cnblogs.com/woniurunfast/p/14968426.html
swagger的注解说明官方文档 https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations
http://localhost:8080/swagger-ui.html 这个页面就可以看到swagger界面
在配置swagger的过程中遇见的问题
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
解决方案是:
因为Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher
解决:在application.properties里配置
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER

浙公网安备 33010602011771号