1.Redis的启动和关闭

本文详细介绍了如何通过修改配置文件启动Redis服务,并提供了具体的步骤和命令。此外,还讲解了如何关闭Redis服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一:启动redis

首先创建myredis目录,赋值原生的redis配置文件redis.conf到该目录下,修改配置文件,将图中标的地方改为yes

找到redis安装目录,进入src目录下:/redis/redis-3.0.0/src

执行命令,启动redis:./redis-server /myredis/redis.conf,我们使用复制并修改后的配置文件启动redis。

执行命令:./redis-cli -p 6379 进入redis

第二:关闭redis

The use of configuration keys that have been renamed was found in the environment: Property source 'applicationConfig: [classpath:/application.yml]': Key: spring.redis.database Line: 18 Replacement: spring.data.redis.database Key: spring.redis.host Line: 16 Replacement: spring.data.redis.host Key: spring.redis.password Line: 19 Replacement: spring.data.redis.password Key: spring.redis.port Line: 17 Replacement: spring.data.redis.port Key: spring.resources.cache.period Line: 33 Replacement: spring.web.resources.cache.period Key: spring.resources.chain.cache Line: 37 Replacement: spring.web.resources.chain.cache Key: spring.resources.chain.gzipped Line: 35 Replacement: spring.web.resources.chain.compressed Property source 'Config resource 'class path resource [application.yml]' via location 'optional:classpath:/'': Key: spring.redis.database Line: 18 Replacement: spring.data.redis.database Key: spring.redis.host Line: 16 Replacement: spring.data.redis.host Key: spring.redis.password Line: 19 Replacement: spring.data.redis.password Key: spring.redis.port Line: 17 Replacement: spring.data.redis.port Key: spring.resources.cache.period Line: 33 Replacement: spring.web.resources.cache.period Key: spring.resources.chain.cache Line: 37 Replacement: spring.web.resources.chain.cache Key: spring.resources.chain.gzipped Line: 35 Replacement: spring.web.resources.chain.compressed Each configuration key has been temporarily mapped to its replacement for your convenience. To silence this warning, please update your configuration to use the new keys. 什么问题
最新发布
08-22
<think>好的,用户提供的错误信息是关于Spring Boot配置文件中一些属性键已经被弃用,并建议替换为新的键。首先,我需要确认这些被弃用的属性在当前使用的Spring Boot版本中是否仍然有效,以及新键的具体用法。 用户提到的属性包括spring.redis.*spring.resources.*相关的键。例如,spring.redis.database需要替换为spring.data.redis.database。这可能是因为Spring Boot在更新版本中对配置属性进行了重新组织,将一些模块的配置归入更具体的命名空间下,比如data.redisweb.resources。 接下来,我需要检查这些属性在当前项目中的使用位置,确保替换后的键在配置文件中正确应用。同时,需要注意替换后是否需要调整其他相关配置,或者是否有其他相关的属性也需要更新,以避免潜在的配置错误。 此外,用户可能还关心如何处理这些警告信息,是否需要立即更新配置文件,或者是否有其他替代方案。比如,如果暂时无法修改配置文件,是否有办法抑制这些警告,但长期来看还是建议更新到新键以确保未来的兼容性。 还需要考虑不同Spring Boot版本之间的差异,用户可能正在升级Spring Boot版本时遇到这些问题。因此,需要确认用户当前使用的版本以及推荐的更新版本,并提供相应的迁移指南或文档链接,帮助用户顺利完成配置更新。 另外,用户可能对替换后的属性是否会影响应用程序的行为有疑问。例如,某些属性可能在新版本中有不同的默认值或处理方式,需要验证这些变更是否会影响应用的功能,尤其是在生产环境中。 最后,总结解决方案时,需要分步骤指导用户如何替换旧键,检查相关配置,并建议测试环境中的验证步骤,确保更新后的配置文件不会导致应用启动失败或功能异常。</think>这是 **Spring Boot 2.4+ 版本** 引入的配置属性迁移警告,提示你使用的部分配置键已被弃用(Deprecated),需要替换为新的命名规范。虽然旧键仍能正常工作(Spring 会自动映射),但建议更新配置以避免未来版本兼容性问题。 --- ### 🔍 问题原因 Spring Boot 从 **2.4 版本开始**,对配置属性的命名规则进行了标准化,主要变化包括: 1. **模块化命名空间**: - 例如 `spring.redis.*` 被归入 `spring.data.redis.*`(更明确归属 `spring-data-redis` 模块)。 2. **Web 资源配置调整**: - `spring.resources.*` 被归入 `spring.web.resources.*`(明确归属 Web 模块)。 --- ### 📝 需要替换的配置项 | 旧键(已弃用) | 新键(推荐使用) | 配置作用 | |----------------|------------------|----------| | `spring.redis.database` | `spring.data.redis.database` | Redis 数据库索引 | | `spring.redis.host` | `spring.data.redis.host` | Redis 主机地址 | | `spring.redis.password` | `spring.data.redis.password` | Redis 密码 | | `spring.redis.port` | `spring.data.redis.port` | Redis 端口 | | `spring.resources.cache.period` | `spring.web.resources.cache.period` | 静态资源缓存时间 | | `spring.resources.chain.cache` | `spring.web.resources.chain.cache` | 静态资源链缓存 | | `spring.resources.chain.gzipped` | `spring.web.resources.chain.compressed` | 静态资源链压缩支持 | --- ### ✅ 解决方案 1. **更新 `application.yml` 配置文件** 将旧键替换为新键(示例): ```yaml spring: data: redis: host: localhost port: 6379 password: database: 0 web: resources: cache: period: 3600 chain: cache: true compressed: true ``` 2. **验证配置是否生效** 启动应用后检查日志,确认是否仍有警告。如果配置正确,警告会消失。 3. **抑制警告(不推荐)** 如果暂时无法更新配置,可通过以下方式关闭警告(不建议长期使用): ```yaml spring: main: allow-legacy-aliases: false # 关闭旧键自动映射(慎用,可能导致配置失效!) ``` --- ### 📌 注意事项 1. **Spring Boot 版本差异** - 该警告仅出现在 **Spring Boot 2.4+** 版本,旧版本(如 2.3.x)无需修改。 - 在 **Spring Boot 3.x** 中,旧键可能被完全移除,必须更新配置。 2. **属性默认值变化** 某些属性在新命名空间下可能有不同默认值(例如 `spring.web.resources.chain.strategy` 的默认策略),需检查文档确认行为是否变化。 3. **IDE 自动提示** 使用 IntelliJ IDEA 或 Spring Tools Suite 时,新键会提供更好的自动补全文档提示。 --- ### 📚 参考资料 - [Spring Boot 2.4 配置属性迁移指南](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Configuration-Changelog) - [Spring Boot 3.0 移除旧键的官方说明](https://docs.spring.io/spring-boot/docs/3.0.0-M3/reference/html/configuration-metadata.html#configuration-metadata-changes) ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值