springboot(查漏补缺)

  1. spring-boot-starter-parent作用
    1. 在pom.xml中引入spring-boot-start-parent,spring官方的解释叫什么stater poms,它可以提供dependency management,也就是说依赖管理,引入以后在申明其它dependency的时候就不需要version了,后面可以看到。
  2. spring-boot-starter-web作用
    1. springweb核心组件
  3. spring-boot-maven-plugin作用
    1. 如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven 的spring-boot:run的话是不需要此配置的。(我在测试的时候,如果不配置下面的plugin也是直接在Main中运行的。)
  4. @enbaleAutoConfiguration
    1. 自动配置
  5. springapplication.run(类名.class,args)
    1. 标识为启动类
  6. @SpringBootApplication 包括(configuration,enbaleAutoConfiguration,componentscan)
  7. @EnableConfigurationProperties(value = { DBConfig1.class, DBConfig2.class })
    1. 启动加载配置类
  8. log4j记录日志

     

  9. springboot本地缓存
    1. 依赖
      1. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency>
    2. 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:内存数量最大时是否清除。

    3.  使用缓存
      1. @CacheConfig(cacheNames = "baseCache")
        public interface UserMapper {
            @Select("select * from users where name=#{name}")
            @Cacheable
            UserEntity findName(@Param("name") String name);
        }

    4. 清除缓存
      1.  
        @Autowired
        private CacheManager cacheManager;
        @RequestMapping("/remoKey")
        public void remoKey() {
            cacheManager.getCache("baseCache").clear();
        }

  10. springboot集成redis做缓存
    1. @EnableCaching 开启缓存
    2. <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>
       
    3. 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
       
    4. @Autowired private StringRedisTemplate stringRedisTemplate;
      1. 类上面的注解 @CacheConfig(cacheNames="") 这个算是文件夹名称 
        方法上面就是@Cacheable(key)加缓存   @CacheEvict(key)删除
  11.  热部署
    1. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>true</scope> </dependency>
  12. 定时任务
    1. @scheduled创建定时任务
      1. @EnableScheduling 开启定时任务
      2. cron详解
        1. @Scheduled(fixedDelay = 5000)延迟执行

        2. fixedrate=5000 定时执行,每隔5s执行
        3. cron(* * * * * * *  ),从做左到右依次为秒,分,时,天,月,周
        4. 统配符
          1. * 表示每
          2. ?忽略
          3. / 每隔
          4. -区间
          5. ,枚举, 15,20,30  到这个3时间点执行时
          6. L last最后 第四个位置的L就表示最后一天
          7. w 表示工作日 是工作日 比如第四个位置的15W表示15号附近最近的工作日
          8. # :周定位,语义相当于每月的第几个周几 比如例4中的第六个位置的2#3就表示第三个周一。
  13. 多环境配置
    1. spring.profiles.active=pre
      
      application-dev.properties:开发环境
      application-test.properties:测试环境
      application-prod.properties:生产环境
      application-pre.properties:预生产环境

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值