当前位置: 首页 > news >正文

企业网站设计过程中必须重视的问题之一哪个网站可以做前端项目

企业网站设计过程中必须重视的问题之一,哪个网站可以做前端项目,古镇灯饰网站建设,顺义手机网站设计设置database 不生效剖析 前言配置加载类问题commons-pool 对象池 主页传送门:📀 传送 前言 事情是这样的 今天在拉取了同事的代码做redis缓存设置的时候,发现即使已经设置了database, 但是存数据的时候还是用的默认0数据库。这引起了我的好…

设置database 不生效剖析

  • 前言
  • 配置
  • 加载类
  • 问题
    • commons-pool 对象池

在这里插入图片描述

主页传送门:📀 传送

前言

  事情是这样的 今天在拉取了同事的代码做redis缓存设置的时候,发现即使已经设置了database, 但是存数据的时候还是用的默认0数据库。这引起了我的好奇,遂开始琢磨是什么情况造成的这种现象。

配置

在这里插入图片描述

上述仅为测试代码问题,为了便于维护可以这么写,

spring:redis:host: ${REDIS_HOST:localhost}port: ${REDIS_PORT:6379}password: ${REDIS_PASSWORD:}database: ${REDIS_DATABASE:0}

加载类

然后通过RedisConfiguration 加载

@ConfigurationProperties("spring.redis")
public class RedisConfiguration {private String host;private int port;private String password;private int database;// getters and setters...
}

问题

  上网找了一系列的文章都没解决,后来仔细观察研究发现是database多了个空格,正确的该是这样,没想到一个空格浪费了这么多时间

在这里插入图片描述
  信心满满的以为这就万事大吉了,结果一运行发现依然不可以,后又开始检查,最后发现是少了几个依赖

在这里插入图片描述
发现没有引入commons-pool2依赖,加上了依赖之后再运行发现已经切换了
在这里插入图片描述

commons-pool 对象池

  引入Commons Pool对象池,用于缓存Redis连接的原因是因为Lettuce本身是基于Netty的异步驱动,在异步访问时并不需要创建连接池,但基于Servlet模型的同步访问时,连接池是有必要的。目的是为了复用对象,以减少创建对象的开销,所以一定记得要加这个依赖。


/*** Creates an instance that can be served by the pool and wrap it in a* {@link PooledObject} to be managed by the pool.** @return a {@code PooledObject} wrapping an instance that can be served by the pool** @throws Exception if there is a problem creating a new instance,*    this will be propagated to the code requesting an object.*/PooledObject makeObject()throws Exception;/*** Destroys an instance no longer needed by the pool.* <p>* It is important for implementations of this method to be aware that there* is no guarantee about what state <code>obj</code>will be in and the* implementation should be prepared to handle unexpected errors.* </p> * <p>* Also, an implementation must take in to consideration that instances lost* to the garbage collector may never be destroyed.* </p>** @param p a {@code PooledObject} wrapping the instance to be destroyed** @throws Exception should be avoided as it may be swallowed by*    the pool implementation.** @see #validateObject* @see ObjectPool#invalidateObject*/void destroyObject(PooledObject p)throws Exception;/*** Ensures that the instance is safe to be returned by the pool.** @param p a {@code PooledObject} wrapping the instance to be validated** @return <code>false</code> if <code>obj</code>is not valid and should*        be dropped from the pool, <code>true</code>otherwise.*/boolean validateObject(PooledObject p);/*** Reinitializes an instance to be returned by the pool.** @param p a {@code PooledObject} wrapping the instance to be activated** @throws Exception if there is a problem activating <code>obj</code>,*    this exception may be swallowed by the pool.** @see #destroyObject*/void activateObject(PooledObject p)throws Exception;/*** Uninitializes an instance to be returned to the idle object pool.** @param p a {@code PooledObject} wrapping the instance to be passivated** @throws Exception if there is a problem passivating <code>obj</code>,*    this exception may be swallowed by the pool.** @see #destroyObject*/void passivateObject(PooledObject p)throws Exception;

注意:
  Jedis 和Lettuce 是Java 操作Redis 的客户端。
在Spring Boot 1.x 版本默认使用的是Jedis ,而在Spring Boot 2.x 版本默认使用的就是Lettuce。
所以如果你用的是1.x版本的话 需要把 RedisConnectionFactory factory 替换为LettuceConnectionFactory lettuceConnectionFactory

在这里插入图片描述

  如果喜欢的话,欢迎 🤞关注 👍点赞 💬评论 🤝收藏  🙌一起讨论你的支持就是我✍️创作的动力!					  💞💞💞
http://www.yayakq.cn/news/922692/

相关文章:

  • 电商网站制作教程北京数字智慧展厅设计咨询
  • 深圳网站开发哪个好页面设计流程
  • 网站网站做代理赚钱吗平面图用什么软件做
  • 不要域名能建网站么redhat7部署wordpress
  • 360站长工具网站不备案违法吗
  • 中煤第一建设公司网站网站制作寻找客户
  • 网站建设对于企业发展的优势电子商务网站设计物流方案
  • 多个链接的网站怎么做的wordpress预缓存
  • 中国老区建设促进会网站wordpress土豆
  • 重庆一品建设集团有限公司网站建行的官网网址是什么
  • 汉中市网站建设中国招标投标网
  • 遵义网站建公司微网站如何做微信支付宝支付宝支付
  • 什么叫网站被k中山网站搜索引擎优化
  • 壹财富 网站开发企业网站建设实训小结
  • 网站开发怎么接单视觉设计包括哪些内容
  • 推荐网站建设服务商昆明建个网站哪家便宜
  • 网站开发u盘128够吗电子印章在线制作免费
  • 西安企业网站搭建centos7 wordpress
  • 网站开发看书南京网络公司平台
  • 网站建设企业云市场网站绝对布局
  • 公司网站网页制作建议logo设计 效果图
  • 私人找人做网站拼多多网店怎么开
  • 做盗版视频网站犯法吗搜索引擎优化的英文
  • 微信公众号里的小网站怎么做的苏州中心有什么好玩的
  • 网站建设哪一家好做礼品公司网站的费用
  • 手把手做网站页面定制型网站建设推广
  • 云虚拟主机建设网站一定要域名太原百度快速优化排名
  • 建什么网站如何做国外网站彩票的推广
  • 集团高端网站建设国外便宜域名注册商
  • 支付网站建设费公众号入口官网