Failed to bind properties under ‘spring.redis.port‘ to int:

具体报错信息如下:

​
Description:

Failed to bind properties under 'spring.redis.port' to int:

    Property: spring.redis.port
    Value: 6379;
    Origin: class path resource [application.properties] - 19:20
    Reason: failed to convert java.lang.String to int

Action:

Update your application's configuration

​

数据类型错误,不能把String转换为int


解决方法

找到properties文件,

把分号去掉就OK了

 再次运行,启动正常。

Spring框架中绑定 `spring.data.redis.password` 属性到 `java.lang.String` 时出现 `BindException` 错误,可按以下方法解决: ### 确保Jasypt依赖添加 在Maven项目的 `pom.xml` 中添加Jasypt依赖: ```xml <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.4</version> </dependency> ``` ### 配置Jasypt加密密钥 可通过系统环境变量或配置文件来配置密钥。 使用系统环境变量时,在Linux系统中运行以下命令: ```bash export JASYPT_ENCRYPTOR_PASSWORD=your-secret-key java -jar your-application.jar ``` 在Windows系统中: ```bash set JASYPT_ENCRYPTOR_PASSWORD=your-secret-key java -jar your-application.jar ``` 也可在配置文件中配置,在 `application.properties` 中添加: ```properties jasypt.encryptor.password=your-secret-key ``` 或在 `application.yml` 中: ```yaml jasypt: encryptor: password: your-secret-key ``` ### 检查属性加密格式 加密的值需以 `ENC()` 包裹,例如: ```properties spring.data.redis.password=ENC(encrypted-password-value) ``` 或在 `application.yml` 中: ```yaml spring: data: redis: password: ENC(encrypted-password-value) ``` ### 检查配置类 若使用自定义配置类绑定属性,确保配置类能正确绑定,示例如下: ```java import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; @Configuration @ConfigurationProperties(prefix = "spring.data.redis") public class RedisConfig { private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } ``` ### 检查Spring Boot版本兼容性 确保Jasypt Spring Boot Starter的版本与Spring Boot版本兼容,不同版本的Spring Boot对Jasypt的支持可能不同,建议参考Jasypt官方文档选择合适版本。 ### 调试与日志输出 在开发环境下,可开启Jasypt的调试日志,在 `application.properties` 中添加: ```properties logging.level.com.github.ulisesbocchio.jasyptspringboot=DEBUG ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值