Introduction to Docker and Docker containers in Java

java-featured-image

In short, Docker is a tool that allows you to build, deploy and run applications easily by the usage of so-called containers. These containers let us package all the essentials such as libraries and dependencies. In addition, the containers run on the host operation system. There are many benefits that come when we use Docker. It…

Continue reading

PathVariable annotation in Spring

spring-featured-image

Just like @RequestParam, @PathVariable annotation is used to extract data from HTTP request . However, they differ slightly. The difference is that @RequestParam gets parameters from the URL while @PathVariable simply extracts them from the URI. Example Let’s imagine you had a website that supported the following URL: http://www.yourwebsite.net/employee/1 1 in the URL above represents…

Continue reading

RequestBody annotation in Spring

spring-featured-image

The @RequestBody annotation can be used for handling web requests. More specifically, it is used to bind a method parameter with the body of a request and the way it works is HttpMessageConverter converts the request’s body based on the type of the content of the request. Syntax <modifier> <return-type> <method-name> (@RequestBody <type> <name>) { }…

Continue reading

Interceptors in Spring

spring-featured-image

In Spring, Interceptors, as the name suggests, intercept we requests through implementing HandlerInterceptor interface. It provides us with methods that allow us to intercept incoming requests that is getting processed by the controller class or the response that has been processed by the controller class. The methods that the interface provides us with are: preHandle() – returns true…

Continue reading

Dependency Injection in Spring Example

spring-featured-image

In this tutorial you are going to learn what Dependency Injection in Spring is, how it works and how you can use it. What is Dependency Injection? Dependency Injection is one of the fundamentals of Spring which you must know. When you create a complex application, chances are you are going to have different objects…

Continue reading

How to perform unit testing for Controllers and Services

spring-featured-image

As you may be well aware, testing is very important. In this tutorial therefore, you will learn how to do just that! Testing. And more specifically, you will learn how to perform that testing on Controllers and Services. Controllers Normal controller does 1 of 2 things: renders a view or handles form submission Let’s look at…

Continue reading

Installing and configuring MySQL database and server for Spring usage

spring-featured-image

In the end of this tutorial, you will have installed the right MySQL products needed to develop applications in Spring. You will need two essential things: MySQL Database and MySQL Server. Follow the steps below. Configuring the MySQL Database Visit https://www.mysql.com/downloads/ and then select Community downloads, like so: On the next page, you will see…

Continue reading

How to handle Login authentication in Spring

spring-featured-image

In this article, you are going to learn how to use Spring Security to achieve a login authentication functionality. The login page represents a form which asks for details such as username and password. That same login page can be done in Angular and the authentication process itself will be performed by Spring Security. There…

Continue reading

Introduction to Spring Security and how to Set it up

spring-featured-image

In this tutorial you are going to learn how to secure your web application using the Spring Security including user authentication, authorization and more. Spring Security – Introduction Spring Security is a customizable authentication framework. It is the standard when it comes to securing Spring-based applications. It provides both authentication and authorization. Authorization is also…

Continue reading

How to create RESTful web services with Spring

spring-featured-image

When we are dealing with RESTful web services, we need to be using @RestController annotation which basically represents the @Controller and @ResponseBody annotations. When we use @RequestMapping for our methods, we can add an attribute which is called produces which specifies that the output sent to the user will be in JSON format. Example Employee.java public class…

Continue reading

What is OAuth2-based authentication and authorization in Spring

spring-featured-image

OAuth2 allows third-party applications to receive a limited access to an HTTP service which is either on behalf of a resource owner or by allowing a third-party application obtain access on its own behalf. Thanks to OAuth2, service providers and consumer applications can interact with each other in a secury way. Workflow There are a…

Continue reading

Introduction to MVC Framework in Spring

spring-featured-image

MVC stands for Model-View-Controller and Spring supports it. The great thing about the MVC pattern is that it separates different aspects of the application like inputs, business logic and user interface.  This pattern is so widely used that it even has a song about it. The three components in the MVC pattern are Model, View, Controller,…

Continue reading

Autowired Annotation in Spring

spring-featured-image

@Autowired annotation is a relatively new style of implementing a Dependency Injection. It allows you to inject other beans into another desired bean. Similar to the @Required annotation, the @Autowired annotation can be used to “autowire” bean on setter methods as well as constructors and properties.. @Autowired Annotation on Setter Methods Please note that when…

Continue reading

Core concepts and Advice Types in AOP in Spring

spring-featured-image

If you are familiar with Spring, you’ve probably heard of Aspect Oriented Programming (AOP). That’s one of the main components of the Spring framework. However, no previous experience in AOP is needed. It is focused for complete beginners who want to understand how AOP framework in Spring works. In Object Oriented Programming, modularity of an…

Continue reading

How to use the MySQL connector in Java

java-featured-image

Before testing the MySQL connection from a Java program, we’ll need to add the MySQL JDBC library to the classpath.  We will need to download the mysql-connector-java-*.jar file from the downloads page: Now, depending upon your work environment (e.g. Eclipse or Command line) you will have to do either one: If working with Eclipse IDE,…

Continue reading