# Java Microservices with Spring Boot and Spring Cloud

**URL:** <https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054>\
**Category:** Developer Blog Comments\
**Created:** [May 21, 2019, 8:40pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054 "2019-05-21T20:40:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [May 21, 2019, 8:40pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/1 "2019-05-21T20:40:17Z")

</div>

[Java Microservices with Spring Boot and Spring Cloud](https://developer.okta.com/blog/2019/05/22/java-microservices-spring-boot-spring-cloud)

This tutorial shows you how to build a microservices architecture with Spring Boot and Spring Cloud.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 11, 2019, 9:20pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/2 "2019-06-11T21:20:23Z")

</div>

**Gregg Zahn**

Kinda messy. I think the best approach is using JWT and validate the token in the gateway if downstream microservices are secure. If not secure, add token validation in a filter in each microservice.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 20, 2019, 6:35pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/3 "2019-06-20T18:35:36Z")

</div>

**Matt Raible**

Yep! That’s what the code in this tutorial does.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [June 26, 2019, 7:15pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/4 "2019-06-26T19:15:05Z")

</div>

**George Kofi**

Thanks again Matt for this nice piece. I have a question though, how do I implement logout functionality in this sample.  
Thanks

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [July 8, 2019, 11:09pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/5 "2019-07-08T23:09:33Z")

</div>

**Matt Raible**

Hello George - I wrote another tutorial that covers logout. See its [Logout with OAuth 2.0 and OIDC](https://developer.okta.com/blog/2019/04/15/testing-spring-security-oauth-with-junit#logout-with-oauth-2-0-and-oidc "https://developer.okta.com/blog/2019/04/15/testing-spring-security-oauth-with-junit#logout-with-oauth-2-0-and-oidc") section for code you can use to implement logout on the client.

Unfortunately, server-side logout is not yet possible. Follow [our Spring Boot Starter’s issue 126](https://github.com/okta/okta-spring-boot/issues/126 "https://github.com/okta/okta-spring-boot/issues/126") for more info.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 30, 2019, 2:30pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/6 "2019-08-30T14:30:53Z")

</div>

**SaNtu Yadav**

where is the “/cars” endpoint in car-service so that FeignClient will call to fetch data  
and how FetchClient works, if you can explain to me i will be thankfull to you  
my e-mail: [info.santu1993@gmail.com](mailto:info.santu1993@gmail.com)

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 31, 2019, 6:02pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/7 "2019-08-31T18:02:06Z")

</div>

**Matt Raible**

It’s created by the RepositoryRestResource annotation. This annotation creates REST endpoints for you to CRUD the entity it manages.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 16, 2019, 11:49pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/8 "2019-09-16T23:49:14Z")

</div>

**Dean Schulze**

On Ubuntu-19.04 httpie gave me an error:

$ http [https://start.spring.io/sta…](https://start.spring.io/starter.zip "https://start.spring.io/starter.zip") javaVersion==11 artifactId==discovery-service name==eureka-service dependencies==cloud-eureka-server baseDir==discovery-service | tar -xzvf -  
gzip: stdin has more than one entry–rest ignored  
tar: Child returned status 2  
tar: Error is not recoverable: exiting now

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 17, 2019, 1:28am UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/9 "2019-09-17T01:28:19Z")

</div>

**Dean Schulze**

Solved this by replacing

| tar -xzvf -

with

-o [discovery.zip](http://discovery.zip "discovery.zip")

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 17, 2019, 1:44am UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/10 "2019-09-17T01:44:30Z")

</div>

**Dean Schulze**

Can you please explain what is happening with this:

`@BeanApplicationRunner init(CarRepository repository) { return args -> { Stream.of(“Ferrari”, “Jaguar”, “Porsche”, “Lamborghini”, “Bugatti”, “AMC Gremlin”, “Triumph Stag”, “Ford Pinto”, “Yugo GV”).forEach(name -> { repository.save(new Car(name)); }); repository.findAll().forEach(System.out::println); };}`

How does this return an ApplicationRunner?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 17, 2019, 5:06pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/11 "2019-09-17T17:06:12Z")

</div>

**pavan kumar**

He is inserting some fake data and ensuring that they are present in DB by printing them out using Db query. ApplicationRunner requires the user to implement just one method. Author just did that by using a lambda.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 18, 2019, 4:09pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/12 "2019-09-18T16:09:56Z")

</div>

**Dean Schulze**

I understand what he is doing with the repository, but what is he doing with the args variable which is of type org.springframework.boot.ApplicationArguments?

Java allows providing a lambda in place of a SAM (single abstract method) class instance. Is that what he’s doing or is this some Java 11 magic?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 18, 2019, 4:22pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/13 "2019-09-18T16:22:45Z")

</div>

**Dean Schulze**

Finding more mysteries with this code construct. If I put this statement before the return statement I get a compile error:

ApplicationArguments args\_ = args;

The javac cannot find the symbol args. And before adding this statement there was no import for ApplicationArguments.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 19, 2019, 11:41pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/14 "2019-09-19T23:41:07Z")

</div>

**Dean Schulze**

When I run the cloned source code under JDK 11 I get an empty array for localhost:8080/cool-cars. The localhost:8080/cars and localhost:8080/home work, though.

The only change I made was to the two [application.properties](http://application.properties "application.properties") files where I used my okta.oauth2 URL and credentials.

Can anyone confirm that this problem is caused by JDK 11?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 20, 2019, 1:21am UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/15 "2019-09-20T01:21:20Z")

</div>

**Matt Raible**

I’ve seen this behavior as well. The first time I hit `/cool-cars`, it returns an empty array. If I refresh my browser, it populates as expected. I’m not sure why this happens.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 1, 2019, 4:34pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/16 "2019-10-01T16:34:07Z")

</div>

**Marc-Arthur Pierre-Louis**

I am experiencing the same problem. I set a breakpoint in the goodCars() method in the api gateway in an Eclipse debugger and saw that a Collection of empty car objects was being returned. So I added a getter in the car-service application and verified that a collection of valid cars was being returned in the goodCars method and yet I was still getting am empty list in the browser. This led me to think that the fallback method was being hit all the time. So I disabled Hystrix , first in the code (commented it out) and I got a valid list in the browser. I also disabled Hystrix in [application.properties](http://application.properties "application.properties") while leaving the Hystrrix annotatiom intact in the code. I also got a valid list in the browser. In debugging this my breakpoint would be hit and I would see that the empty list is already returned without me stepping through the code. This leads me to think that there is a synchronization problem where the fallback is hit while the goodCars method is also hit.

I am curious if anybody has seen this strange behavior.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 2, 2019, 8:19am UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/17 "2019-10-02T08:19:20Z")

</div>

**Shanika Wijerathna**

Hi Matt, Thanks for the great blog. Spring Security will use HttpSession to store the access token which makes the application depend on http session state right? If we deploy that in an environment like kubernetes where you will have multiple instances of the app (Or gateway) it will not work since the session is not shared. What approach would you recommend to solve that problem? Going for implicit flow, or issue a separate JWT token to maintain user data? Highly appreciate any input. Thanks

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 2, 2019, 1:58pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/18 "2019-10-02T13:58:23Z")

</div>

**Matt Raible**

If you use oauth2Login() with Spring Security, yes, it will store the access token in the session. If you setup your Spring Boot app as a resource server, it will validate the JWT and act in a stateless manner. If you’re using multiple instances of your app with oauth2Login(), I’d recommend you use something like [Spring Session](https://spring.io/projects/spring-session "https://spring.io/projects/spring-session") and back it with Redis or Hazelcast.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 2, 2019, 2:00pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/19 "2019-10-02T14:00:04Z")

</div>

**Matt Raible**

There’s no Java 11 magic in this code. It’s just Java 8 lambdas.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [October 2, 2019, 6:48pm UTC](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054/20 "2019-10-02T18:48:13Z")

</div>

**Shanika Wijerathna**

Thanks Matt!

[Next page](https://devforum.okta.com/t/java-microservices-with-spring-boot-and-spring-cloud/17054.md?page=2)
