Posts

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 ...