![](/img/trans.png)
[英]Dependency 'org.springframework.boot:spring-boot-starter-security:2.2.6.RELEASE' not found
[英]The dependency spring-boot-starter-security is not found in a simple Maven project
我正在尝试在一个简单的 spring 引导应用程序 (Maven) 中注入 spring-boot-starter-security 依赖项。 我试图从实际的 Spring 网站的“保护 Web 应用程序”教程中复制此依赖项,我还尝试将其与 spring 安全测试依赖项和 thymeleaf spring 安全依赖项一起实现。
因此,这里是出现错误“未找到”的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
这是完整的 pom 文件:
4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.1.RELEASE com.homehero homehero 0.0.1 战争
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<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>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我觉得有必要提前感谢大家,如果我遗漏了一些非常愚蠢的东西,我很抱歉,我真的希望我没有!
我解决了这个问题。
长话短说,我的一个朋友建议用 Spring Initializer 做一个新项目,这次从头开始添加“Spring Boot Security”依赖项。 之后,我只需要比较 pom 文件。 唯一的区别是新项目有:
<scope>test</scope>
线。 我将它添加到我的初始项目中,第一个依赖项不再出现错误。 第二个依赖是 Thymeleaf spring 安全之一,为了修复这个我添加了:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
到我的 pom 文件。
所以这就是依赖关系现在看起来的样子:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
就是这样,谢谢你们也提供的所有答案。
查看父 POM.xml 文件的版本。 当我将版本更改为 2.0.0 时,我的项目找到了依赖项。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
我有同样的问题。 按着这些次序:
1-删除找不到的依赖项。 2-同步您的项目。 3- 添加依赖项。 4-再次同步项目。
它对我有用希望对其他人有用:)
Not sure how you are creating project.I can tell you simple solution,which is to go to Spring Initializer,link for which is https://start.spring.io/
在那里您可以添加所有所需的依赖项,然后只需单击“生成”,它将下载您的项目。您可以将项目导入 IDE 并运行 maven 构建。我尝试使用 Z38008DD81C2F4D7985ECF6E2D.3CE18AF1 仅启动它作为您提到的版本为我工作,应该为你工作。
另外,我建议你使用 Intellij IDE,它默认支持 maven,所以它会让你轻松。你可以从这里下载 Intellij 免费版:Z5E056C500A1insC4B6A7110B50 /#section=windows
希望它会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.