0

I am following a Springboot tutorial on a website I found. The site tells us to add various dependencies to our pom.xml file. I added the web and thymeleaf dependencies through the Spring Initializr. Hwoever, I realized that I forgot to add the security dependency. When I try to edit my code and add the security dependency by typing:

<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-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
Rahul
  • 181
  • 1
  • 2
  • 13
  • Whats the actual error or problem you're seeing? – Mike Aug 21 '19 at 21:21
  • I thought I added it to the original post, my bad. This is the error: Dependency 'org.springframework.boot:spring-boot-starter-security:' not found more... (Ctrl+F1) – Rahul Aug 21 '19 at 21:36
  • Are you using `spring-boot-starter-parent` as the parent in your own? – Mike Aug 22 '19 at 01:48
  • I believe is, here is the rest of my code from the pom.xml file. 4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.7.RELEASE springtest spring-boot-starter 0.0.1-SNAPSHOT spring-boot-starter Demo project for Spring Boot 11 – Rahul Aug 22 '19 at 02:25
  • Can you update the question with the full POM? Comments don't support multiline formatting so it's difficult to piece it all together. – Mike Aug 22 '19 at 02:45
  • Also, what happens if you try to generate a new starter app on spring initializer and include security, does that work? – Mike Aug 22 '19 at 02:45

1 Answers1

0

You should either inherit your project from spring-boot-starter-parent:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.7.RELEASE</version>
</parent>

The parent project provides the following features:

  • Java 1.8 as the default compiler level.
  • UTF-8 source encoding.
  • A Dependency Management section, inherited from the spring-boot-dependencies pom, that manages the versions of common dependencies. This dependency management lets you omit <version> tags for those dependencies when used in your own pom.
  • An execution of the repackage goal with a repackage execution id.
  • Sensible resource filtering.
  • Sensible plugin configuration (exec plugin, Git commit ID, and shade).
  • Sensible resource filtering for application.properties and application.yml including profile-specific files (for example, application-dev.properties and application-dev.yml)

Or use the spring-boot-dependencies BOM:

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.7.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Using the BOM is the way to go when you would not like to inherit from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use or you may prefer to explicitly declare all your Maven configuration. You would still keep the benefit of the dependency management, but not the plugin management.

Both solutions will allow you to omit versions of Spring dependencies.

madhead
  • 31,729
  • 16
  • 153
  • 201