Spring
-
Spring AOP Example Tutorial – Aspect, Advice, Pointcut, JoinPoint, Annotations, XML Configuration
Spring Framework is developed on two core concepts – Dependency Injection and Aspect Oriented Programming ( Spring AOP). Spring AOP We have already seen how Spring Dependency Injection works, today we will look into the core concepts of Aspect-Oriented Programming and how we can implement it using Spring Framework. Spring AOP Overview Most of the enterprise applications have some common crosscutting concerns that are applicable to different types of Objects and modules. Some of the common crosscutting concerns are logging,…
-
Spring @Configuration Annotation
Spring @Configuration annotation is part of the spring core framework. Spring Configuration annotation indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application. Spring @Configuration Spring @Configuration annotation allows us to use annotations for dependency injection. Let’s understand how to create Spring Configuration classes. Let’s create a simple java bean class. package com.journaldev.spring; public class MyBean { public MyBean() { System.out.println(“MyBean instance created”); } }…
-
Spring Interview Questions and Answers
I have posted a lot of Spring Tutorials recently. This post will help you get through Spring interview Questions explaining the core concepts in detail. Spring Framework is one of the most popular Java EE frameworks for web applications. Dependency Injection and Aspect-Oriented Programming are at the heart of the Spring framework. If you are good at Spring Framework, the chances of getting selected get really high in Java interviews. Pro Tip: Core Java is the base of any Java-based…
-
Key Components and Internals of Spring Boot Framework
In my previous post “Introduction to Spring Boot”, we have discussed about Spring Boot basics. Now we will discuss about “What are the main components of Spring Boot” and “How Spring Boot works under-the-hood”. Key Components of Spring Boot Framework Spring Boot Framework has mainly four major Components. Spring Boot Starters Spring Boot AutoConfigurator Spring Boot CLI Spring Boot Actuator NOTE:- In addition to these four major components, there are two more Spring Boot components: Spring Initilizr Spring Boot IDEs…
-
Spring Annotations
Spring Annotations allows us to configure dependencies and implement dependency injection through java programs. Spring Annotations Spring framework implements and promotes the principle of control inversion (IOC) or dependency injection (DI) and is in fact an IOC container. Traditionally, Spring allows a developer to manage bean dependencies by using XML-based configuration. There is an alternative way to define beans and their dependencies. This method is a Java-based configuration. Unlike the XML approach, Java-based configuration allows you to manage bean components…
-
Spring @Bean Annotation
Spring @Bean Annotation is applied on a method to specify that it returns a bean to be managed by Spring context. Spring Bean annotation is usually declared in Configuration classes methods. In this case, bean methods may reference other @Bean methods in the same class by calling them directly. Spring @Bean Example Let’s say we have a simple class as below. package com.journaldev.spring; public class MyDAOBean { @Override public String toString() { return “MyDAOBean”+this.hashCode(); } } Here is a Configuration…
-
Spring Bean Scopes
Spring Bean Scopes allows us to have more granular control of the bean instances creation. Sometimes we want to create bean instance as singleton but in some other cases we might want it to be created on every request or once in a session. Spring Bean Scopes There are five types of spring bean scopes: singleton – only one instance of the spring bean will be created for the spring container. This is the default spring bean scope. While using…
-
Spring Boot MongoDB
Welcome to Spring Boot MongoDB example. Spring Boot is the easiest way to spin a spring project quickly and MongoDB is the most popular NoSQL database. Let’s see how to integrate spring with MongoDB database. Spring Boot MongoDB We need following APIs to work with Spring Boot and MongoDB database. Spring Data MongoDB Spring Boot There are two approaches through which we can connect to MongoDB database – MongoRepository and MongoTemplate. We will try to establish what one API offers…
-
Spring Boot Redis Cache
Spring Boot Redis Cache In this post, we will setup up a sample Spring boot application and integrate it with Redis Cache. While Redis is an Open source in-memory data structure store, used as a database, cache and message broker, this lesson will demonstrate only the caching integration. We will make use of Spring Initializr tool for quickly setting up the project. Spring Boot Redis Project Setup We will make use of Spring Initializr tool for quickly setting up the…