首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在简单的Maven项目中找不到依赖spring-boot-starter-security

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

Stack Overflow用户
提问于 2020-07-19 23:05:34
回答 3查看 994关注 0票数 0

我正在尝试将spring- boot -starter-security依赖注入到一个简单的spring boot应用程序(Maven)中。我试图从实际Spring网站的“保护Web应用程序”教程中复制这个依赖项,我还尝试将它与spring安全测试依赖项和thymeleaf安全依赖项一起实现。

下面是出现错误"not found“的依赖项:

代码语言:javascript
复制
    <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版本com.homehero homehero 0.0.1 war

代码语言:javascript
复制
<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>

我觉得有必要提前感谢你们,如果我错过了一些非常愚蠢的东西,我很抱歉,我真的希望我没有!

EN

回答 3

Stack Overflow用户

发布于 2020-07-20 01:52:16

我解决了这个问题。

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

代码语言:javascript
复制
<scope>test</scope>

线路。我将其添加到我的初始项目中,第一个依赖项不再收到该错误。第二个依赖项是Thymeleaf spring安全依赖项,为了修复这个依赖项,我添加了:

代码语言:javascript
复制
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-java8time</artifactId>
    </dependency>

到我的pom文件中。

现在,这些依赖项看起来就像这样:

代码语言:javascript
复制
    <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
EN

Stack Overflow用户

发布于 2020-10-29 22:12:42

查看父POM.xml文件的版本。当我将版本更改为2.0.0时,我的项目将创建依赖项。

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
票数 0
EN

Stack Overflow用户

发布于 2020-07-19 23:37:23

我不知道你是如何创建项目的,我可以告诉你一个简单的解决方案,那就是进入Spring Initializer,它的链接是https://start.spring.io/

在这里你可以添加所有你需要的依赖项,然后点击Generate,这将会下载你的project.You,只需在你的集成开发环境中导入项目并运行maven build.I即可。我只尝试了你提到的Spring boot版本2.3.1,它适用于我,也应该适用于你。

另外,我建议你使用Intellij IDE,默认情况下它支持maven,所以它会让you.You更容易从这里下载Intellij免费版本:https://www.jetbrains.com/idea/download/#section=windows

希望能对你有所帮助。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62981975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档