I am working on building an oAuth2 application using spring boot. However, there are various sample projects in Github using spring-security-oauth2
and spring-cloud-starter-oauth2
.
Do we have specific scenarios where we can use a specific jar among both for an application?
Though Spring cloud is mainly used for distributed systems. There are a lot of implementations on Github using spring-cloud-starter-oauth2
for even non-distributed applications. Thanks.

- 726
- 2
- 6
- 12
2 Answers
To resolve complex dependency management, Spring Boot starters were introduced. Starter POMs are a set of dependency descriptors (combines multiple commonly used dependencies into one POM) which otherwise you could also manually include in your application individually. Starters are available for web, test, data jpa, security, mailing and more. If it is not starter, it is a module: a simple artifact.
If you want to work with web, you could include tomcat, mvc and jackson all by yourself (manually) - a lot of dependencies for a single simple application. Instead, you just introduce one starter dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Coming to your question:
spring-security-oauth2 is an artifact of group org.springframework.security.oauth which supports oAuth2 (only) for Spring Security (not cloud), whereas spring-cloud-starter-oauth2 is a set of multiple dependencies like a starter web dependency above. This is OAuth2 starter for Spring Cloud that is only if you are working with Spring cloud. This starter comes with bundle of out-of-the-box dependencies underneath the OAuth2 framework for Spring Cloud like SSO, OAuth2 client.

- 1,006
- 11
- 27
-
1"This starter comes with bundle of out-of-the-box dependencies underneath ....". Like how do you know that? Where is that mentioned, I can not find any info about it. Where can i find what packages are included – Alexander Jul 25 '20 at 12:43
-
1@Alexander Spring initially moved oauth2 to spring cloud started but as of version 2.4.0.M1 it was moved to spring security. You will be able to verify on https://start.spring.io/ that oauth2 cloud dependency is only in version >=2.0.0.RELEASE and <2.4.0.M1 – Ujjwal Pathak Mar 19 '21 at 16:08
Spring initially moved oauth2 to spring cloud started but as of version 2.4.0.M1 it was moved to spring security. You will be able to verify on start.spring.io that oauth2 cloud dependency is only in version >=2.0.0.RELEASE and <2.4.0.M1

- 646
- 12
- 21