1 回答

TA貢獻1878條經驗 獲得超4個贊
看起來您當前的spring-security依賴項僅適用于test范圍。
如果我們按照教程進行操作,它會聲明您必須為添加以下依賴項WebSecurityConfig:
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
...
</dependencies>
請注意,此處未設置范圍,即它將是默認范圍,即compile.
您可能需要在更改依賴項后手動重新導入 maven 項目:
重新導入后,里面的依賴pom.xml應該不會顯示為紅色了。
輕微更新
可以 146% 確定,這是我的 pom.xml 有效:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-securing-web</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
更新 2 - 修復實際當前問題
實際上問題(以及問題文本本身)import只是.HttpSecurityWebSecurityConfig
所以加入
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
將使代碼編譯并SpringSiteApplication啟動。
更新 3 - 我們通過 TeamViewer 調查后真正的問題是什么。
尚未下載 Spring 依賴項,因為計算機無法訪問中央 Maven 存儲庫 ( https://repo.maven.apache.org/maven2 )。禁用 Windows 防火墻后,連接開始工作。
IDEA 在更新 repo 索引時太慢了,但命令行mvn install幫助最終下載了庫。之后,IDEA 也開始顯示導入的類。
添加回答
舉報