Posts

Showing posts from February, 2024

11. Spring MVC @RequestMapping

  Spring MVC @RequestMapping In spring MVC @RequestMapping plays the role of mapping URL to the method of controller class. In Spring MVC application we generally use a URL which calls the Controller. In the Controller to map a given URL we use @RequestMapping annotation. RequestMapping can be used in many ways. 1. RequestMapping at Class Level 2. RequestMapping only at Method level 3. @RequestMapping annotations at class level as well as method levels 4. RequestMapping using HTTP methods 5. @RequestMapping with @RequestParam 6. @RequestMapping with @PathVariable 1. RequestMapping at Class Level @RequestMapping can be added at class Level. This way the URI provided will act as base URI for all other methods in the Controller class. @Controller @RequestMapping(value = "/employee") public class EmployeeController { // Methods.... } Now any requests with /employee as URL will hit this Controller class. 2. RequestMapping only at Method level @RequestMapping is optional for class ...

10. Spring - MVC Framework

Image
  Introduction to Spring MVC Framework - Spring MVC is used to develop the web applications that uses MVC design pattern. By using Spring MVC we can build flexible and loosely coupled web applications. - The MVC design pattern helps in seperating the business logic, presentation logic and controller logic. - Models are responsible for encapsulating the application data.  - The Views render response to the user with the help of the model object .  - Controllers are responsible for receiving the request from the user and calling the back-end services. Spring MVC will make application development faster, cost effective and flexible. Advantage of Spring MVC Framework - Clear separation of responsibilities because it implements MVC design pattern. - Loose coupling among Model, View and Controller. - Inbuilt front controller. - Simplified Validation implementation. - Simplified Exception Handling. - Internationalization logic is simplified compared to other frameworks. - Spring...

9. Spring ORM Framework

  Spring ORM      The Spring Framework integrates well with ORM frameworks like Hibernate, Java Persistence API (JPA), Java Data Objects (JDO) and iBATIS SQL Maps. Spring provides resource management, data access object (DAO) implementations, and transaction strategies.     Spring ORM (Object-Relational Mapping) framework simplifies the integration of Java applications with databases. When combined with Hibernate, it offers a powerful and flexible solution for managing database operations.  1. Object-Relational Mapping (ORM):    - ORM is a programming technique used to map objects from an object-oriented domain model to a relational database model, and vice versa.    - It abstracts the complexities of SQL queries and database interactions, allowing developers to work with objects directly.    - Instead of writing SQL queries, developers work with domain objects directly, and the ORM framework handles the translation o...

8. Spring JDBC Framework

  Why we are not use plain/normal  JDBC ? -  Using plain old JDBC for working with a database, it becomes complicated to use an unnecessary code for opening/closing database or handle exceptions etc. Spring JDBC  - The Spring JDBC framework is a part of the larger Spring Framework that provides comprehensive support for JDBC (Java Database Connectivity) operations.  - JDBC is a standard Java API for database access, and the Spring JDBC framework simplifies the process of database interaction by handling common tasks, managing resources, and providing a higher level of abstraction. - Spring JDBC gives several approaches and different classes to use it with the database. So, you just have to define the connection parameters.  - One of the key components in Spring JDBC is the JdbcTemplate class.  - It is a central framework class which manages all database communication such as executing SQL, updating statements etc. Also, it catches exceptions of JDBC an...

7. Spring Expression Language ( SpEL )

  Spring Expression Language ( SpEL ) - Spring Expression Language (SpEL) is a powerful and flexible expression language that is widely used in the Spring Framework for defining and evaluating expressions at runtime.  - SpEL provides a standardized way to work with expressions in various parts of the Spring ecosystem, such as annotations, XML configuration, and programmatic configuration. - Supports Parsing and executing expression with the help of @Value annotation. - We can categorize elements in code, such as classes, variables, methods, constructors, objects, symbols, characters, numerics, operators, keywords, and special symbols, each serving a distinct purpose. These entities collectively contribute to the code's functionality by returning specific values. Syntax : - @Value("#{Expression}") Here are some key features and concepts of Spring Expression Language: 1. Basic Syntax:    SpEL expressions are enclosed in #{...} or ${...} syntax. The choice between #{} a...

6. Spring Configuration Metadata

  - The Spring IoC (Inversion of Control) container is responsible for managing and controlling the lifecycle of Java objects, also known as beans.  - Configuration metadata is essential for the Spring IoC container to understand how to create, configure, and manage these beans.  There are three main ways to provide this configuration metadata: 1. XML-based Configuration:    - In XML-based configuration, you use XML files to define the configuration metadata for your Spring application.    - The configuration typically includes information about beans, their dependencies, and how they should be wired together.    - An example of XML-based configuration:            <!-- applicationContext.xml -->      <beans xmlns="http://www.springframework.org/schema/beans"             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           ...

5. Spring Beans Autowiring & Annotation Based Configuration(Autowiring)

Image
  Autowiring - Auto-wiring, also known as automatic wiring, is a feature of the Spring Framework that automatically wires beans together by matching the types of the properties, constructor arguments, or method arguments of the beans. - Spring Autowiring is a feature provided by the Spring IoC (Inversion of Control) container that allows for automatic resolution of dependencies between beans. - Instead of explicitly configuring the relationships between beans in the XML configuration file using `<constructor-arg>` and `<property>` elements, autowiring allows the Spring container to automatically inject the required dependencies. - Autowiring in Spring Beans helps in reducing the efforts of writing properties. - If autowiring is enabled then spring container will take care about injecting the dependencies, and no need to configure into an xml file explicitly. - Autowiring can't be used to inject primitive and string values, it will only supported if the dependancies are ...

4. Spring Bean Scopes and Bean Lifecycle

Image
  What is Scope? A scope refers to the life cycle of a bean. For example how long does the bean live, how many instances are created for the bean and how the bean is shared in the spring environment etc. Spring framework supports six type of scopes that are described below: singleton prototype request session global-session application 1. Singleton Scope : - This is default bean scope and Spring container creates only one instance of the bean.It is cached in memory.  - All requests for the bean will return a shared reference to the same bean. - If In the bean definition the scope is not given, then by default singleton scope is assumed.  - In a given Spring container a singleton scoped bean will be instantiated only once and the same will be used for its lifetime.Singleton scoped beans are mostly used for stateless beans. How to define the bean scope We can define the scope of a bean in two ways. 1. Singleton Scope using XML In singleton bean scope, we need to assign sing...

3. Spring IoC Container

Image
Spring IoC Container   - Spring Framework provides two of the most fundamental and important packages, they are the org.springframework.beans and org.springframework.context packages.  -  The Spring container is the core of Spring Framework.  - The container, use for creating the objects and configuring them. Also, Spring IoC Containers use for managing the complete lifecycle from creation to its destruction.  - It uses Dependency Injection (DI) to manage components that make up the application.   - Spring containers are responsible for creating bean objects and injecting them into the classes.  - The container uses configuration metadata which represent by Java code, annotations or XML along with Java POJO classes. How the Spring IoC Container Works: 1. Bean Definition:    - Beans in a Spring application are defined by creating a bean definition, which is essentially a metadata that defines how the bean should be created, configure...

2. Spring Framework Module (Architecture)

Image
  Spring Framework Architecture The Spring Framework is a comprehensive framework for enterprise Java development. It provides a modular and organized way to build enterprise-level applications. The framework is divided into several modules, each addressing specific concerns.  Types  1. The Core Container: 2. Data Access / Integration 3. The Web   4. Miscellaneous (AOP)   1. Spring Core Container:    CORE: This module provides the fundamental parts of the framework,  its including the IoC (Inversion of Control) container and Dependency Injection features.   BEAN : It deals with the creation and management of Java objects (beans) and their dependencies.A sophisticated implementation of factory pattern called BeanFactory, is provided by, Bean module. CONTEXT : This module builds on the core and beans modules, providing a way to access application objects and services in a consistent manner. It has access rights for any objects that de...

1. Spring Overview

Image
  Spring Framework  - The Spring Framework is a comprehensive framework for enterprise Java development.  - It provides a wide range of features and functionalities that simplify the development of Java applications, particularly in the domain of enterprise and web applications.  - The framework is known for its modularity, scalability, and ease of integration. What is Spring  - It was developed by Rod Johnson in 2003. - Spring is a lightweight framework. - Spring is a Dependency injection framework to make java application loosely couple. - Spring framework makes the easy developement of javaEE (enterprise ) application. Why to Learn Spring? - Spring is the most popular application development framework for enterprise Java. Millions of developers around the world use Spring Framework to create high performing, easily testable, and reusable code. - Spring is a tool that helps make it easier to build software, like apps or websites. -  Learning Spring is val...