You need to enable JavaScript to run this app. IntelliJ Spring Java11项目提示Cannot resolve symbol 'BCrypt'如何解决
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ Spring Java11项目提示Cannot resolve symbol 'BCrypt'如何解决

解决方案

场景1:使用Spring Security内置BCrypt

  • 首先移除spring-security-core依赖的手动版本号,如果你使用的是Spring Boot项目,父POM已经统一管理安全组件版本,手动指定版本极易出现依赖冲突:
<dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-core</artifactId>
</dependency>
  • 刷新Maven依赖:右键pom.xml → 选择Maven → 点击Reload Project,或点击IDEA右侧Maven面板的刷新按钮
  • 确认导包路径正确,Spring Security内置BCrypt类的完整路径为org.springframework.security.crypto.bcrypt.BCrypt,不要错误导入其他路径或搜索不存在的顶层BCrypt类
  • 测试代码示例:
import org.springframework.security.crypto.bcrypt.BCrypt;

public class BcryptTest {
    public static void main(String[] args) {
        // 密码加密
        String encodePassword = BCrypt.hashpw("你的原始密码", BCrypt.gensalt());
        // 密码校验
        boolean isMatch = BCrypt.checkpw("你的原始密码", encodePassword);
        System.out.println(isMatch);
    }
}

场景2:使用jbcrypt独立依赖

  • 出现红色警告大概率是依赖下载失败,先删除本地Maven仓库中org/mindrot目录,之后重新刷新Maven依赖
  • 如果下载依然失败,检查Maven的settings.xml配置,替换为国内镜像源后重试
  • 正确导包路径为import org.mindrot.jbcrypt.BCrypt;

通用排查方案

如果以上操作后依然报错,执行IDEA缓存清理重启操作:

  1. 点击顶部菜单栏File → 选择Invalidate Caches...
  2. 勾选Clear file system cache and local history选项
  3. 点击Invalidate and Restart等待IDEA重启完成后重新检查

内容的提问来源于stack exchange,提问作者Jenny L

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.19 10:27:07