- spring-boot-starter-parent作用
- 在pom.xml中引入spring-boot-start-parent,spring官方的解释叫什么stater poms,它可以提供dependency management,也就是说依赖管理,引入以后在申明其它dependency的时候就不需要version了,后面可以看到。
- spring-boot-starter-web作用
- springweb核心组件
- spring-boot-maven-plugin作用
- 如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven 的spring-boot:run的话是不需要此配置的。(我在测试的时候,如果不配置下面的plugin也是直接在Main中运行的。)
- @enbaleAutoConfiguration
- 自动配置
- springapplication.run(类名.class,args)
- 标识为启动类
- @SpringBootApplication 包括(configuration,enbaleAutoConfiguration,componentscan)
- @EnableConfigurationProperties(value = { DBConfig1.class, DBConfig2.class })
- 启动加载配置类
- log4j记录日志
- springboot本地缓存
- 依赖
- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency>
-
1. 2. name:缓存名称。 3. maxElementsInMemory:缓存最大个数。 4. eternal:对象是否永久有效,一但设置了,timeout将不起作用。 5. timeToIdleSeconds:设置对象在失效前的允许闲置时间(单位:秒)。仅当eternal=false对象不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大。 6. timeToLiveSeconds:设置对象在失效前允许存活时间(单位:秒)。最大时间介于创建时间和失效时间之间。仅当eternal=false对象不是永久有效时使用,默认是0.,也就是对象存活时间无穷大。 7. overflowToDisk:当内存中对象数量达到maxElementsInMemory时,Ehcache将会对象写到磁盘中。 8. diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区。 9. maxElementsOnDisk:硬盘最大缓存个数。 10. diskPersistent:是否缓存虚拟机重启期数据 Whether the disk store persists between restarts of the Virtual Machine. The default value is false. 11. diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒。 12. memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用) 13. clearOnFlush:内存数量最大时是否清除。
- 使用缓存
-
@CacheConfig(cacheNames = "baseCache") public interface UserMapper { @Select("select * from users where name=#{name}") @Cacheable UserEntity findName(@Param("name") String name); }
-
- 清除缓存
-
@Autowired private CacheManager cacheManager; @RequestMapping("/remoKey") public void remoKey() { cacheManager.getCache("baseCache").clear(); }
-
- 依赖
- springboot集成redis做缓存
- @EnableCaching 开启缓存
-
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency>
-
spring.redis.database=0 //redis数据库 spring.redis.host=localhost //redis地址 spring.redis.port=6379 //d端口 spring.redis.password=123456 //密码 spring.redis.pool.max-idle=8 spring.redis.pool.min-idle=0 spring.redis.pool.max-active=8 / spring.redis.pool.max-wait=1 spring.redis.timeout=5000
- @Autowired private StringRedisTemplate stringRedisTemplate;
- 类上面的注解 @CacheConfig(cacheNames="") 这个算是文件夹名称
方法上面就是@Cacheable(key)加缓存 @CacheEvict(key)删除
- 类上面的注解 @CacheConfig(cacheNames="") 这个算是文件夹名称
- 热部署
- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency>
- 定时任务
- @scheduled创建定时任务
- @EnableScheduling 开启定时任务
- cron详解
-
@Scheduled(fixedDelay = 5000)延迟执行
- fixedrate=5000 定时执行,每隔5s执行
- cron(* * * * * * * ),从做左到右依次为秒,分,时,天,月,周
- 统配符
- * 表示每
- ?忽略
- / 每隔
- -区间
- ,枚举, 15,20,30 到这个3时间点执行时
- L last最后 第四个位置的
L
就表示最后一天 - w 表示工作日 是工作日 比如第四个位置的
15W
表示15号附近最近的工作日 #
:周定位,语义相当于每月的第几个周几 比如例4中的第六个位置的2#3
就表示第三个周一。
-
- @scheduled创建定时任务
- 多环境配置
-
spring.profiles.active=pre application-dev.properties:开发环境 application-test.properties:测试环境 application-prod.properties:生产环境 application-pre.properties:预生产环境
-
springboot(查漏补缺)
最新推荐文章于 2023-07-08 15:35:34 发布