在一个简单的Maven项目中找不到依赖项spring-boot-starter-security

时间:2020-07-19 15:05:34

标签: java spring spring-boot maven spring-security

我试图将spring-boot-starter-security依赖项注入一个简单的spring boot应用程序(Maven)中。我尝试从实际的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 弹簧启动启动器父母 2.3.1。发布 com.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>

我觉得有必要提前感谢大家,如果我错过了一些愚蠢的事情,对不起,我真的希望我没有!

3 个答案:

答案 0 :(得分:1)

我解决了这个问题。

长话短说,我的一个朋友建议使用Spring Initializer做一个新项目,这次是从一开始就添加“ Spring Boot Security”依赖项。之后,我只需要比较pom文件。唯一的区别是新项目有一个:

<scope>test</scope>

行。我将其添加到我的初始项目中,并且第一个依赖项不再收到该错误。第二个依赖性是Thymeleaf弹簧安全性,为了解决这个问题,我添加了:

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

就是这样,谢谢你们也提供了所有答案。

答案 1 :(得分:0)

看看父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>

答案 2 :(得分:-1)

不确定您如何创建项目。我可以告诉您一个简单的解决方案,该方法是转到Spring Initializer,其链接为https://start.spring.io/

您可以添加所有必需的依赖项,然后单击“生成”,这将下载您的项目。您只需将项目导入IDE并运行maven build。我仅在使用Spring引导版本2.3.1时尝试过提到它对我有用,应该对你有用。

此外,我建议您使用Intellij IDE,它默认情况下具有maven支持,因此它将为您带来方便。您可以从此处下载Intellij免费版: https://www.jetbrains.com/idea/download/#section=windows

希望它会对您有所帮助。