You can get hold of Spring Security in several ways. You can download a packaged distribution from the main Spring Security page, download individual jars from the Maven Central repository (or a Spring Maven repository for snapshot and milestone releases) or, alternatively, you can build the project from source yourself.html
A minimal Spring Security Maven set of dependencies typically looks like the following:java
<dependencies> <!-- ... other dependency elements ... --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>4.2.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>4.2.10.RELEASE</version> </dependency> </dependencies>
If you are using additional features like LDAP, OpenID, etc. you will need to also include the appropriate Section 2.4.3, 「Project Modules」. web
All GA releases (i.e. versions ending in .RELEASE) are deployed to Maven Central, so no additional Maven repositories need to be declared in your pom.spring
<repositories> <!-- ... possibly other repository elements ... --> <repository> <id>spring-snapshot</id> <name>Spring Snapshot Repository</name> <url>http://repo.spring.io/snapshot</url> </repository> </repositories>
If you are using a milestone or release candidate version, you will need to ensure you have the Spring Milestone repository defined as shown below:apache
<repositories> <!-- ... possibly other repository elements ... --> <repository> <id>spring-milestone</id> <name>Spring Milestone Repository</name> <url>http://repo.spring.io/milestone</url> </repository> </repositories>
Spring Security builds against Spring Framework 4.3.21.RELEASE, but should work with 4.0.x. The problem that many users will have is that Spring Security’s transitive dependencies resolve Spring Framework 4.3.21.RELEASE which can cause strange classpath problems.api
spring-framework-bom
within your
<dependencyManagement>
section of your
pom.xml
as shown below:
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>4.3.21.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
This will ensure that all the transitive dependencies of Spring Security use the Spring 4.3.21.RELEASE modules.app
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 refer to Maven’s Introduction to the Dependency Mechanism documentation. 這種方法使用Maven的「物料清單」(BOM)概念,僅適用於Maven 2.0.9+。有關如何解析依賴關係的其餘詳細信息,請參閱Maven的依賴關係機制簡介文檔。
A minimal Spring Security Gradle set of dependencies typically looks like the following:框架
dependencies { compile 'org.springframework.security:spring-security-web:4.2.10.RELEASE' compile 'org.springframework.security:spring-security-config:4.2.10.RELEASE' }
All GA releases (i.e. versions ending in .RELEASE) are deployed to Maven Central, so using the mavenCentral() repository is sufficient for GA releases.maven
repositories { mavenCentral() }
If you are using a SNAPSHOT version, you will need to ensure you have the Spring Snapshot repository defined as shown below:ide
repositories { maven { url 'https://repo.spring.io/snapshot' } }
If you are using a milestone or release candidate version, you will need to ensure you have the Spring Milestone repository defined as shown below:
repositories { maven { url 'https://repo.spring.io/milestone' } }
By default Gradle will use the newest version when resolving transitive versions. This means that often times no additional work is necessary when running Spring Security 4.2.10.RELEASE with Spring Framework 4.3.21.RELEASE. However, at times there can be issues that come up so it is best to mitigate this using Gradle’s ResolutionStrategy as shown below:
configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> if (details.requested.group == 'org.springframework') { details.useVersion '4.3.21.RELEASE' } } }
This will ensure that all the transitive dependencies of Spring Security use the Spring 4.3.21.RELEASE modules.