This guide shows you how to install Spring Tool Suite in Eclipse
Continue readingSpring
Create Simple Spring Web App with STS
This tutorial will show you how to build a simple web app using Spring Framework and STS (Spring Tool Suite). It’s a beginner guide and it will help you if you are new to Spring or STS.
Continue readingIntroduction to Spring Web Framework
In this article I will explain the key concepts behind Spring Framework and how to use it further to build web apps.
Continue readingIntroduction to Docker and Docker containers in Java
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 readingImplementing Controllers in Spring
Controllers’ main purposes in Spring are intercepting incoming http requests, sends data to Model for processing and finally gets processed data from the Model and passes the very same data to View which is going to render it. A very top-level overview of the written above: Now, let’s build a simple app which will serve…
Continue readingPathVariable annotation in Spring
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 readingRequestBody annotation in Spring
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 readingRequestParam annotation in Spring
The RequestParam annotation is used when we want to read web request parameters in our controller class. In other words, the front end is sending us some parameters (from a filled form for example) with keys. Use case Suppose we had a form which purpose was to add an employee to the database. Each employee would have:…
Continue readingInterceptors in Spring
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 readingIOC in Spring
A famous example of explaining the Inversion of Control (IOC) concept is the Holywood principle which states “Dont’ call us, we will call you”. Without a doubt, it is a very accurate analogy, hence the amount of people referencing it as an analogy. Usually, classes create dependencies. However, IOC gives us the opposite functionality –…
Continue readingJava Spring IoC Container Example
In a nutshell, the IoC container is responsible for instantiating/creating and configuring an object and assembling the dependencies between objects. You might be wondering.. how does IoC container receive the data to do the above-mentioned? The answer is from 1 of 3 places: XML fle, Java code or Java annotations. IoC Container is a framework…
Continue readingDispatcher servlet in Spring
The dispatcher servlet is the most important component in the Spring Web MVC. Why is the dispatcher servlet the most important component though? Because it acts as a glue, meaning it receives an incoming URL and finds the correct methods and views. It receives the URL via HTTP request. You can also think of it…
Continue readingDependency Injection in Spring Example
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 readingImplementing Spring MVC Controllers
This tutorial describes different ways to implement Spring MVC Controllers and gives examples.
Continue readingIntroduction to Spring ORM
In this tutorial, you are going to learn what Spring ORM is and how to use it. What is Spring ORM? Spring ORM is covers many technologies like Hibernate, iBatis and JPA. Spring provides integration classes thanks to which, each of the technologies mentioned are able to be implemented following the Spring principles of confiugration. The…
Continue readingWhat is DAO and how to use it
Before I jump into implementing the classes, let’s first understand what DAO is. If you already know what DAO is, feel free to jump to the code examples. If not, bear with me. DAO stands for Data Access Object and it is a structural pattern which isolates the business layer (logic) from the persistence layer…
Continue readingHow to unit test DAO components
In this tutorial you are going to learn how to create unit tests for DAOs. As a prerequisite, you fundamental knowledge of DAOs is expected. When it comes to testing DAO components, we really have 2 approaches. One is to use the mocking framework Mockito and the other is to create a couple of classes…
Continue readingHow to perform unit testing for Controllers and Services
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 readingInstalling and configuring MySQL database and server for Spring usage
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 readingHow to handle Login authentication in Spring
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 readingIntroduction to Spring Security and how to Set it up
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 readingHow to create RESTful web services with Spring
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 readingCSRF Protection in Spring
In this tutorial you will learn how to protect your application against CSRF. What is CSRF? If you already know what CSRF, feel free to continue without reading this sub-point. But if you don’t, CSRF stands for cross-site request forgery and simply put, it is when attackers make authenticated users to perform an action on the…
Continue readingWhat is OAuth2-based authentication and authorization in Spring
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 readingIntroduction to Spring Boot
In this tutorial you are going to learn what Spring Boot is and how you can start using it. Prerequisites 10-20 minutes of your time familiarity with Maven What is Spring Boot? Spring Boot makes the process of creating a stand-alone Spring based application very easy and simple. By using the Spring Boot Java-based framework,…
Continue readingIntroduction to MVC Framework in Spring
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 readingIntroduction to JDBC in Spring
In this tutorial you are going to learn what the JDBC module is and hopefully you will be able to find use cases after you are done reading it. Now, let’s create a very simple table that represents an employee. CREATE TABLE Employee ( ID INT NOT NULL AUTO_INCREMENT, NAME VARCHAR(20) NOT NULL, AGE INT…
Continue readingHow to dockerize a Spring application
In this tutorial, you are going to learn what is Docker and how we can use it to Dockerize a Spring application. Dockerfile Dockerfile is just a .txt file. Dockerfile allows you to run commands that help you build an image. These commands can be useful if you want to specify the layers of the image. One…
Continue readingAutowired Annotation in Spring
@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 readingCore concepts and Advice Types in AOP in Spring
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 readingIntroduction to Spring Bean
In this tutorial you are going to learn what Sping Bean is and how to use it. What is Spring Bean? Beans are the objects that construct the application and are managed by the Spring IoC container. The formal definition from the Spring Framework documentation is: In Spring, the objects that form the backbone of…
Continue readingHow to use the MySQL connector in Java
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