簡體   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