繁体   English   中英

无法在Spring中导入安全性库

[英]Trouble importing security libraries in Spring

我正在尝试利用spring提供的BCrypt库。 我查阅了许多教程,但是由于一些奇怪的原因,几乎没有教程试图显示build.gradle文件应包含哪些内容来访问它们。 目前,我有这个:

dependencies {
    ....
    compile group: 'org.springframework.security', name: 'spring-security-crypto', version: '5.0.8.RELEASE'
}

在我的实际Java文件中,我有这个:

package project;

import org.springframework.security.config.annotation.web.configuration;
import org.springframework.security.crypto.password;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

但是,在尝试构建时会看到以下错误:

error: cannot find symbol import org.springframework.security.config.annotation.web.configuration;
                                                     ^
symbol:   class configuration
location: package org.springframework.security.config.annotation.web

error: package org.springframework.security.crypto does not exist 
import org.springframework.security.crypto.password;

error: cannot find symbol public class SecurityConfig extends WebSecurityConfigurerAdapter {
                                     ^
symbol: class WebSecurityConfigurerAdapter

error: cannot find symbol
    public PasswordEncoder passwordEncoder() {
           ^
symbol:   class PasswordEncoder
location: class SecurityConfig

我缺少了哪些依赖关系,当教程将它们排除在外时如何找到它们?

您似乎正在尝试导入包本身,而不是从包内部导入

代替

import org.springframework.security.config.annotation.web.configuration;

你应该有

import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

请注意,使用IDE将使此操作变得更加容易,因为它将自动为您完成类名并自动添加适当的导入。

综上所述,找到您似乎无法找到的类的依赖项的最佳方法是搜索中央存储库 您可以按简单的类名进行搜索,也可以使用fc: 按完整的类名进行搜索

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM