0
votes

I am trying to inject the spring-boot-starter-security dependency in a simple spring boot application (Maven). I tried to copy this dependency from the "Securing a Web Application" tutorial from the actual Spring website, I also tried to implement it together with the spring security test dependency and thymeleaf spring security dependency.

So here are the dependencies that get the error "not found":

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

And here it is the full pom file:

4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.1.RELEASE com.homehero homehero 0.0.1 war

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

I feel the need to thank y'all in advance and sorry if I'm missing something really stupid, I really hope I'm not!

3
Please add the error log output ....khmarbaise
Hi @khmarbaise, I don't get an error in the log. I can run the application without encountering any kind of problem.Alex Naie

3 Answers

1
votes

I solved the problem.

Long story short, a friend of mine suggested doing a new project with Spring Initializer and this time add from the beginning the "Spring Boot Security" dependency. After that, I just needed to compare the pom files. The only difference was that the new project had a:

<scope>test</scope>

line. I added that to my initial project and the first dependency did not get the error anymore. The second dependency was the Thymeleaf spring security one, in order to fix this one I added:

    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-java8time</artifactId>
    </dependency>

To my pom file.

So this is how the dependencies look together now:

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

That's it, thank you for all the answers you guys also provided.

0
votes

Take a look in the version of parent POM.xml file. When I've changed the version to 2.0.0 my project founds the dependency.

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

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/

There you can add all your required dependencies and then just click on Generate,which will download your project.You can just import the project in your IDE and run maven build.I tried with Spring boot version 2.3.1 only as you mentioned and it worked for me and should work for you.

Also,I would suggest you to user Intellij IDE,which comes with maven support by default,so it will make things easy for you.You can download Intellij free edition from here: https://www.jetbrains.com/idea/download/#section=windows

Hope it will help you.