简体   繁体   English

无法在Spring中导入安全性库

[英]Trouble importing security libraries in Spring

I am trying to make use of the BCrypt library that spring provides. 我正在尝试利用spring提供的BCrypt库。 I've looked up many tutorials, but for some odd reason, almost none of them attempt to show what the build.gradle file should contain to access them. 我查阅了许多教程,但是由于一些奇怪的原因,几乎没有教程试图显示build.gradle文件应包含哪些内容来访问它们。 Currently, I have this: 目前,我有这个:

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

In my actual java file, I have this: 在我的实际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();
    }
}

However, I see these errors when I try to build: 但是,在尝试构建时会看到以下错误:

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

Which dependencies am I missing and how can I find them when the tutorials leave them out? 我缺少了哪些依赖关系,当教程将它们排除在外时如何找到它们?

You seem to be trying to be trying to import the package itself instead of a class from inside the package . 您似乎正在尝试导入包本身,而不是从包内部导入

Instead of 代替

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

you should have 你应该有

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

Note that using an IDE will make this much easier, as it will autocomplete the class names for you and automatically add the appropriate import. 请注意,使用IDE将使此操作变得更加容易,因为它将自动为您完成类名并自动添加适当的导入。

All of this said, the best way to find a dependency for a class you can't seem to find is to search the Central Repository . 综上所述,找到您似乎无法找到的类的依赖项的最佳方法是搜索中央存储库 You can search by simple class name or use fc: to search by full class name . 您可以按简单的类名进行搜索,也可以使用fc: 按完整的类名进行搜索

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

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