This section discusses all you need to know about getting the Spring Security binaries. See Section 2.3, “Source Code” for how to obtain the source code.
Spring Security versions are formatted as MAJOR.MINOR.PATCH such that:
As most open source projects, Spring Security deploys its dependencies as Maven artifacts. The topics in this section provide detail on how to consume Spring Security when using Maven.
Spring Boot provides a spring-boot-starter-security
starter that aggregates Spring Security-related dependencies together.
The simplest and preferred way to use the starter is to use Spring Initializr by using an IDE integration (Eclipse, IntelliJ, NetBeans) or through https://start.spring.io.
Alternatively, you can manually add the starter, as the following example shows:
Example 4.1. pom.xml
<dependencies> <!-- ... other dependency elements ... --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies>
Since Spring Boot provides a Maven BOM to manage dependency versions, you do not need to specify a version. If you wish to override the Spring Security version, you may do so by providing a Maven property, as the following example shows:
Example 4.2. pom.xml
<properties> <!-- ... --> <spring-security.version>5.2.12.RELEASE</spring-security.version> </dependencies>
Since Spring Security makes breaking changes only in major releases, it is safe to use a newer version of Spring Security with Spring Boot. However, at times, you may need to update the version of Spring Framework as well. You can do so by adding a Maven property, as the following example shows:
Example 4.3. pom.xml
<properties> <!-- ... --> <spring.version>5.2.16.RELEASE</spring.version> </dependencies>
If you use additional features (such as LDAP, OpenID, and others), you need to also include the appropriate Chapter 6, Project Modules.
When you use Spring Security without Spring Boot, the preferred way is to use Spring Security’s BOM to ensure a consistent version of Spring Security is used throughout the entire project. The following example shows how to do so:
Example 4.4. pom.xml
<dependencyManagement> <dependencies> <!-- ... other dependency elements ... --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-bom</artifactId> <version>5.2.12.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
A minimal Spring Security Maven set of dependencies typically looks like the following:
Example 4.5. pom.xml
<dependencies> <!-- ... other dependency elements ... --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> </dependency> </dependencies>
If you use additional features (such as LDAP, OpenID, and others), you need to also include the appropriate Chapter 6, Project Modules.
Spring Security builds against Spring Framework 5.2.16.RELEASE but should generally work with any newer version of Spring Framework 5.x.
Many users are likely to run afoul of the fact that Spring Security’s transitive dependencies resolve Spring Framework 5.2.16.RELEASE, which can cause strange classpath problems.
The easiest way to resolve this is to use the spring-framework-bom
within the <dependencyManagement>
section of your pom.xml
as the following example shows:
Example 4.6. pom.xml
<dependencyManagement> <dependencies> <!-- ... other dependency elements ... --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>5.2.16.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
The preceding example ensures that all the transitive dependencies of Spring Security use the Spring 5.2.16.RELEASE modules.
Note | |
---|---|
This approach uses Maven’s “bill of materials” (BOM) concept and is only available in Maven 2.0.9+. For additional details about how dependencies are resolved, see Maven’s Introduction to the Dependency Mechanism documentation. |
All GA releases (that is, versions ending in .RELEASE) are deployed to Maven Central, so no additional Maven repositories need to be declared in your pom.
If you use a SNAPSHOT version, you need to ensure that you have the Spring Snapshot repository defined, as the following example shows:
Example 4.7. pom.xml
<repositories> <!-- ... possibly other repository elements ... --> <repository> <id>spring-snapshot</id> <name>Spring Snapshot Repository</name> <url>https://repo.spring.io/snapshot</url> </repository> </repositories>
If you use a milestone or release candidate version, you need to ensure that you have the Spring Milestone repository defined, as the following example shows:
Example 4.8. pom.xml
<repositories> <!-- ... possibly other repository elements ... --> <repository> <id>spring-milestone</id> <name>Spring Milestone Repository</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories>
As most open source projects, Spring Security deploys its dependencies as Maven artifacts, which allows for first-class Gradle support. The following topics provide detail on how to consume Spring Security when using Gradle.
Spring Boot provides a spring-boot-starter-security
starter that aggregates Spring Security related dependencies together.
The simplest and preferred method to use the starter is to use Spring Initializr by using an IDE integration (Eclipse, IntelliJ, NetBeans) or through https://start.spring.io.
Alternatively, you can manually add the starter, as the following example shows:
Example 4.9. build.gradle
dependencies {
compile "org.springframework.boot:spring-boot-starter-security"
}
Since Spring Boot provides a Maven BOM to manage dependency versions, you need not specify a version. If you wish to override the Spring Security version, you may do so by providing a Gradle property, as the following example shows:
Since Spring Security makes breaking changes only in major releases, it is safe to use a newer version of Spring Security with Spring Boot. However, at times, you may need to update the version of Spring Framework as well. You can do so by adding a Gradle property, as the following example shows:
If you use additional features (such as LDAP, OpenID, and others), you need to also include the appropriate Chapter 6, Project Modules.
When you use Spring Security without Spring Boot, the preferred way is to use Spring Security’s BOM to ensure a consistent version of Spring Security is used throughout the entire project. You can do so by using the Dependency Management Plugin, as the following example shows:
Example 4.12. build.gradle
plugins { id "io.spring.dependency-management" version "1.0.6.RELEASE" } dependencyManagement { imports { mavenBom 'org.springframework.security:spring-security-bom:5.2.12.RELEASE' } }
A minimal Spring Security Maven set of dependencies typically looks like the following:
Example 4.13. build.gradle
dependencies { compile "org.springframework.security:spring-security-web" compile "org.springframework.security:spring-security-config" }
If you use additional features (such as LDAP, OpenID, and others), you need to also include the appropriate Chapter 6, Project Modules.
Spring Security builds against Spring Framework 5.2.16.RELEASE but should generally work with any newer version of Spring Framework 5.x. {JB}
Many users are likely to run afoul of the fact that Spring Security’s transitive dependencies resolve Spring Framework 5.2.16.RELEASE, which can cause strange classpath problems.
The easiest way to resolve this is to use the spring-framework-bom
within your <dependencyManagement>
section of your pom.xml
.
You can do so by using the Dependency Management Plugin, as the following example shows:
Example 4.14. build.gradle
plugins { id "io.spring.dependency-management" version "1.0.6.RELEASE" } dependencyManagement { imports { mavenBom 'org.springframework:spring-framework-bom:5.2.16.RELEASE' } }
The preceding example ensures that all the transitive dependencies of Spring Security use the Spring 5.2.16.RELEASE modules.
All GA releases (that is, versions ending in .RELEASE) are deployed to Maven Central, so using the mavenCentral() repository is sufficient for GA releases. The following example shows how to do so:
If you use a SNAPSHOT version, you need to ensure you have the Spring Snapshot repository defined, as the following example shows:
If you use a milestone or release candidate version, you need to ensure that you have the Spring Milestone repository defined, as the following example shows: