Skip to main content

Posts

How to dockerize a spring boot application

Greetings! Spring boot helps us to create application very quickly. Docker provides us a way to "build, ship and run" our applications. In a world of Microservices, combining these two gives us powerful ways to create and distribute our Java applications. I assume you have enough Spring boot and Docker knowledge and want study further to dockerize Spring boot applications. https://github.com/slmanju/springtime/tree/master/spring-boot-docker Let's create a simple rest service and dockerize it. Step 1: Create Spring boot application Go to https://start.spring.io and fill it as you want. Then add Spring Web Starter as a dependency. This is enough for us create a simple rest service. Download and extract the application. Then add below controller (or anything you like). package com.slmanju.springbootdocker; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HomeC...

How to use Spring Boot with MySQL database

Greetings! Spring Framework simplifies working with databases by auto configuring connections, handling transactions, using ORM tool like hibernate, abstract sql by Spring Data Repository. We are going to focus on how to connect MySQL database with Spring Boot application. Sprint Boot has many defaults. For databases, H2 in-memory database is the default database. It auto-configures in-memory databases even without connection url. Those are good for simple testing. For production use we need to use a database like MySQL. Spring Boot selects HickariCP Datasource due to it is performance. When spring-boot-starter-data-jpa dependency in classpath it automatically pick HickariCP. complete source code this blog post is here . How to configure a database Obviously, to use a database in our application we need; Database driver to connect to database Connection url Database username and password In Spring Boot application we need to provide atleast connection url, otherwise i...

Microservices - Distributed tracing with Spring Cloud Sleuth and Zipkin

Greetings! Microservices are very flexible. We can have multiple microservices for each domain and interact as necessary. But it comes with a price. It becomes very complex when the number of microservices grow. Imagine a situation where you found a bug or slowness in the system. How do you find the root cause by examinig logs? Collect all the logs from related microservices. Pick the starting microservice and find a clue there using some id (userid, businessid, etc). Pick the next microservice and check whether the previous information are there. Keep going until you find which microservice has the bug. I have followed that practise in one of my previous projects. It is very difficult and takes a lot of time to track an issue. This is why we need to use distributed tracing in microservices. One place where we can go and see the entire trace. It helps us by; Asign unique id (correlation id) to all request. Pass unique id across all the microservices automatically. Re...

Cracking Java8 Stream Interview Question

Greetings! I have faced many interviews (too many to be frank) in my career as a software developer. In most of those interviews I have been asked to write a pseudo code for a given problem and implement it in Java. With Java8, this implementation mostly should be in Java8. When I look back all those questions it can be simplified as below. (difficulty may be vary though). Iterate over a given collection (stream) Filter the given data (filter) Transform into another format (map, reduce) Collect data into a collection (collect) or End the stream (forEach, min, etc) Is this familiar to you? This should be. This is what we do in our daily work. But, if you are blindly using it you will see it as a difficult question to answer. You need to have good understanding about intermediate and terminal operations. And, you need to really practise and use in daily work. It is meaningless to pass an interview without knowing these. java-8-streams-intermediate-operations java-8-stream...

Angular - Let's create a starter project

Greetings! Angular has many things to learn though we can skip those and directly create simple project. It will be harder to study all the features first. So here, i'm going to directly create a simple starter project. This is the end result of this tutorial. Install Angular CLI npm install -g @angular/cli ng version Create a project ng new angular-store --routing --style=scss cd angular-store npm install This will create a basic app structure. Run the project ng serve --open # short form ng s -o With zero code, we have a running template. That's some power. Angular Material Let's add material UI design into our project. For more information visit https://material.angular.io/ Below command will add angular material into our project and update neccessary files. ng add @angular/material We want to use material design component in our project. To add material components in a single place let's create a separate module named material and ...