top of page
Search
Writer's picturerussell colwell

Microservices with Spring

Updated: Mar 9, 2020









Today in any cloud architecture microservices are a norm. Having the ability to build small self-contained applications delivers great flexibility to your application and resiliency to your architecture.


In this article we will look at building a microservice using spring, that we can later be consumed by other microservices and deployed into our cloud environment via containerization or any method you prefer.


Our end goal to achieve something like the image below that we can easily move between cloud providers if needed.




 

Step 1.

We need to generate our project (https://start.spring.io/) You will notice int he image I am using Gradle and Java, you can use what ever you are comfortable with I am just the most comfortable with Java and may be using this to improve my Gradle knowledge :).


You can also see that we added Spring Web as a dependency and now just need to click Generate.





Step 2.

Now we need to add our code to the mix. Since we are just standing up a hello world lets just add our RestController to the Application class. We can preak it out later as we add more important functionality like security but for now something simple like this will be helpful with docker wrapping our app.


So below we added the @RestController and the new @GetMapping with the hello method.



Step 3.

Now we re ready to run and test our new super simple microservice! All we need to do is execute the command ./gradlew bootRun in the file directory where we saved our download to and we should see something like the below.


And if you are seeign this you should be able to type http://localhost:8080/hello into your browser and view the rewards of your hard work so far.



In our next post we will containerize before we add on and continue to make a more meaningful REST API to be used in our application.


I hope this was helpful. If so please follow and sign-up for update notifications.

 

Reference Links:

8 views0 comments

Recent Posts

See All

Eureka!

Comments


bottom of page