Skip to content

Commit 92f0aab

Browse files
author
Matt Raible
authored
Add Spring Cloud Gateway section
1 parent 2e351cf commit 92f0aab

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

README.md

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11

22
# Java Microservices with Spring Boot and Spring Cloud 🍃☁️
33

4-
This repository contains examples of how to build a microservices architecture with Spring Boot 2.1, Spring Cloud Greenwich, Netflix Eureka, and Netflix Zuul.
4+
This repository contains examples of how to build a Java microservices architecture with Spring Boot 2.1, Spring Cloud Greenwich, and Netflix Eureka.
55

6-
This repository has two examples in it. One is a bare-bones microservices architecture with Spring Boot, Spring Cloud, Eureka Server, and Zuul. The second is one that's built with JHipster and configured centrally with Spring Cloud Config.
6+
This repository has three examples in it. The first is a bare-bones microservices architecture with Spring Boot, Spring Cloud, Eureka Server, and Zuul. The second is one that's built with JHipster and configured centrally with Spring Cloud Config. The third uses Spring Cloud Gateway and Spring WebFlux to show reactive microservices.
77

88
We think you'll enjoy them both!
99

1010
* See [Java Microservices with Spring Boot and Spring Cloud](https://developer.okta.com/blog/2019/05/22/java-microservices-spring-boot-spring-cloud) for an overview of the first example.
1111
* Read [Java Microservices with Spring Cloud Config and JHipster](https://developer.okta.com/blog/2019/05/23/java-microservices-spring-cloud-config) to learn about microservices with JHipster.
12+
* Refer to [Secure Reactive Microservices with Spring Cloud Gateway](https://developer.okta.com/blog/2019/09/28/reactive-microservices-spring-cloud-gateway) to learn about Spring Cloud Gateway and reactive microservices.
1213

13-
**Prerequisites:** [Java 11](https://sdkman.io/sdks#java).
14+
**Prerequisites:** [Java 11](https://sdkman.io/sdks#java) and an internet connection.
1415

1516
* [Spring Boot + Spring Cloud Example](#spring-boot--spring-cloud-example)
1617
* [JHipster + Spring Cloud Config Example](#jhipster--spring-cloud-config-example)
18+
* [Spring Cloud Gateway Example](#spring-cloud-gateway-example)
1719
* [Links](#links)
1820
* [Help](#help)
1921
* [License](#license)
@@ -47,7 +49,7 @@ okta.oauth2.client-secret=$clientSecret
4749

4850
Then, run all the projects with `./mvnw` in separate terminal windows. You should be able to navigate to `http://localhost:8761` and see the apps have been registered with Eureka.
4951

50-
Then, navigate to `http://localhost:8080/cool-bars` in your browser, log in with Okta, and see the resulting JSON.
52+
Then, navigate to `http://localhost:8080/cool-cars` in your browser, log in with Okta, and see the resulting JSON.
5153

5254
## JHipster + Spring Cloud Config Example
5355

@@ -119,6 +121,57 @@ Create a `ROLE_ADMIN` group (**Users** > **Groups** > **Add Group**) and add you
119121

120122
Now when you hit `http://localhost:8761` or `http://localhost:8080`, you should be able to log in with Okta!
121123

124+
## Spring Cloud Gateway Example
125+
126+
To install this example, run the following commands:
127+
128+
```bash
129+
git clone https://github.com/oktadeveloper/java-microservices-examples.git
130+
cd java-microservices-examples/spring-cloud-gateway
131+
```
132+
133+
The `api-gateway` and `car-service` projects are already pre-configured to be locked down with OAuth 2.0 and Okta. That means if you try to run them, you won't be able to login until you create an account, and an application in it.
134+
135+
If you already have an Okta account, see the **Create a Web Application in Okta** section below. Otherwise, we created a Maven plugin that configures a free Okta developer account + an OIDC app (in under a minute!).
136+
137+
To use it, add the following plugin repository to the gateway project's `pom.xml`:
138+
139+
[source,xml]
140+
----
141+
<pluginRepositories>
142+
<pluginRepository>
143+
<id>ossrh</id>
144+
<releases><enabled>false</enabled></releases>
145+
<snapshots><enabled>true</enabled></snapshots>
146+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
147+
</pluginRepository>
148+
</pluginRepositories>
149+
----
150+
151+
Then run `./mvnw com.okta:okta-maven-plugin:setup` to create an account and configure the gateway to work with Okta.
152+
153+
Copy the `okta.*` properties from the gateway's `src/main/resources/application.properties` to the same file in the `car-service` project.
154+
155+
Then, run all the projects with `./mvnw` in separate terminal windows. You should be able to navigate to `http://localhost:8761` and see the apps have been registered with Eureka.
156+
157+
Then, navigate to `http://localhost:8080/cars` in your browser, log in with Okta, and see the resulting JSON.
158+
159+
### Create a Web Application in Okta
160+
161+
Log in to your Okta Developer account (or [sign up](https://developer.okta.com/signup/) if you don't have an account).
162+
163+
1. From the **Applications** page, choose **Add Application**.
164+
2. On the Create New Application page, select **Web**.
165+
3. Give your app a memorable name, add `http://localhost:8080/login/oauth2/code/okta` as a Login redirect URI and click **Done**.
166+
167+
Copy the issuer (found under **API** > **Authorization Servers**), client ID, and client secret into the `application.properties` of the `api-gateway` and `car-service` projects.
168+
169+
```properties
170+
okta.oauth2.issuer=https://{yourOktaDomain}/oauth2/default
171+
okta.oauth2.client-id=$clientId
172+
okta.oauth2.client-secret=$clientSecret
173+
```
174+
122175
## Links
123176

124177
These examples uses the following open source libraries:

0 commit comments

Comments
 (0)