28.spring 5
28.spring 5
28.spring 5
AKHIL K ANIL
Basics of spring
}
In IoC we do,
class Employee{
Address address;
Employee(Address address){
this.address=address;
Example :
class Employee{
In such case, instance of
Address class is
Address address;
provided by external
Employee(Address address){ source such as XML file
either by constructor or
this.address=address; setter method
}
this.address=address;
}
There are two ways to perform dependency injection in spring :
● By Constructor
● By Setter method
Spring Bean :
In Spring, the objects that form the backbone of your application and that are managed by
the Spring IoC container are called beans. A bean is an object that is instantiated,
assembled, and otherwise managed by a Spring IoC container.
1. JDBC provides an abstract layer of JDBC and eliminates the need for the
developer to manually register the monotonous code associated with
connecting to the database.
2. Spring ORM provides integration with popular ORMs such as Hibernate,
JDO, which are implementations of JPA.
3. The OXM module is responsible for linking the Object / XML – XMLBeans,
JAXB, etc.
4. The JMS (Java Messaging Service) module is responsible for creating,
sending and receiving messages.
5. Transactions supports transaction management for classes that implement
certain methods and POJOs.
Miscellaneous modules
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
</bean>
</beans>
Instantiating container :
Using BeanFactory -
Resource resource=new ClassPathResource("spring.xml");
obj.setBrand(“Audi”);
obj.setYear(2021);
obj.getDetails();
DEPENDENCY INJECTION
Understanding dependency :
Whenever a class A uses another class or interface B, then A depends on B. A cannot carry out it's
work without B, and A cannot be reused without also reusing B. In such a situation the class A is
called the "dependant" and the class or interface B is called the "dependency".
Two classes that uses each other are called "coupled".
❖ Dependency Injection (DI) is a design pattern that removes the dependency from the
programming code so that it can be easy to manage and test the application.
❖ Dependency Injection makes our programming code loosely coupled
❖ In spring DI is a way to achieve IoC
❖ There are two types of dependency injection
<bean id=”car”
class=”...”>
<constructor-arg
ref=”tyre”/>
</bean>
<bean id=”tyre”
class=”...”>
</bean>
Setter-Based dependency injection
Example :
In spring.xml :
<bean id=”car”
class=”...”>
<property
name=”tyre”
ref=”tyre”></prope
rty>
</bean>
<bean id=”tyre”
class=”...”>
</bean>
AUTOWIRING
★ Autowiring feature of spring framework enables you to inject the object dependency implicitly.
★ It internally uses setter or constructor injection
★ Autowiring can't be used to inject primitive and string values. It works with reference only
★ Advantage : It requires the less code because we don't need to write the code to inject the
dependency explicitly
★ Disadvantage : No control of programmer, It can't be used for primitive and string values
Autowiring modes :
byType The byType mode injects the object dependency according to type.
So property name and bean name can be different. It internally calls
setter method.
Bean definitions :
1. Class
2. Name
3. Scope
4. Constructor arguments
5. Properties
6. Autowiring mode
7. Lazy initialization mode
8. Initialization method
9. Destruction method
Scope :
singleton
(Default) Scopes a single bean definition to a single object instance for each Spring IoC container.
prototype
Scopes a single bean definition to any number of object instances.
request
Scopes a single bean definition to the lifecycle of a single HTTP request. That is, each HTTP request has its own instance of a bean
created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.
session
Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.
application
Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of a web-aware Spring ApplicationContext.
websocket
Scopes a single bean definition to the lifecycle of a WebSocket. Only valid in the context of a web-aware Spring ApplicationContext.
Annotation-based container configuration
★ Annotations used : @Required(deprecated), @Autowired,@Qualifier
★ In order to use, include context namespace and <context:annotation-config/> in
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
</beans>
@Autowired :
➢ Use @Autowired annotation on setter methods to get rid of the <property> element in XML configuration
file
➢ When Spring finds an @Autowired annotation used with setter methods, it tries to perform byType
autowiring on the method
➢ A constructor @Autowired annotation indicates that the constructor should be autowired when creating the
bean, even if no <constructor-arg> elements are used while configuring the bean in XML file
@Qualifier :
➢ There may be a situation when you create more than one bean of the same type and want to wire only one
of them with a property. In such cases, you can use the @Qualifier annotation along with @Autowired to
remove the confusion by specifying which exact bean will be wired
Example :
public class Student{
....
@Autowired
@Qualifier("course")
this.course = course;
...}
Java based configuration
● Java-based configuration option enables you to write most of your Spring configuration without XML but with the
help of few Java-based annotations
● Annotations used : @Configuration,@Bean,@Component,@ComponentScan(basePackages=””)
Example :
@Configuration
Instead of defining methods that
public class AppConfig { return bean objects, a more
concise approach is to use
@Bean @Component annotation in
classes and to provide
public Student student() { @ComponentScan annotation in
Configuration class
return new Student(course()); }
@Bean
ctxt.register(AppConfig.class); ctxt.refresh();
course.setCid(1); course.setCourseName("JAVA")
student.setSid(101); student.setSname("Raju");
System.out.println(student);
}
SPRING AOP
AKHIL K ANIL
Aspect oriented programming(aop)
A cross-cutting
concern is a concern
that can affect the whole
application and should be
centralized in one
location in code as
possible, such as
transaction management,
authentication, logging,
security etc
Why AOP?
It provides the pluggable way to dynamically add the additional concern before, after or around the actual logic.
class A{
}
There are 5 methods that starts from m, 2 methods that starts from n and 3 methods that starts from p
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
Additional dependencies needed :
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.3.13</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
<scope>runtime</scope>
</dependency>
● <dependency>
● <groupId>org.aspectj</groupId>
● <artifactId>aspectjrt</artifactId>
● <version>1.6.11</version>
● </dependency>
Schema based AOP(configurations in XML)
In spring.xml :
<bean id=”employeeManager” class=”package.EmployeeManager”></bean>
<aop:config>
<aop:aspect ref=”aspectClass”>
<aop:pointcut id=”ptcut”
expression=”execution(*package.EmployeeManager.getEmployeeById(..))”/>
</aop:aspect>
</aop:config>
Understanding AspectJ pointcut expression
➔ A pointcut expression starts with a pointcut designator (PCD), which is a keyword telling
Spring AOP what to match
➔ The primary Spring PCD is execution, which matches method execution join points
@Pointcut("execution(public Employee package.EmployeeDao.findById(Integer))")
➔ This example pointcut will match exactly the execution of findById method of the
EmployeeDao class. This works, but it is not very flexible
➔ Suppose we would like to match all the methods of the EmployeeDao class, which may
have different signatures, return types, and arguments. To achieve this we may use
wildcards :
@Pointcut("execution(* package.EmployeeDao.*(..))")
➔ Here the first wildcard matches any return value, the second matches any method name,
and the (..) pattern matches any number of parameters (zero or more)
@AspectJ support
❖ @AspectJ refers to a style of declaring aspects as regular Java classes annotated with
annotations
❖ The @AspectJ style was introduced by the AspectJ project as part of the AspectJ 5 release
❖ The @AspectJ support can be enabled with XML- or Java-style configuration
❖ In either case, you also need to ensure that AspectJ’s aspectjweaver.jar
❖ To enable @AspectJ support with Java @Configuration, add the @EnableAspectJAutoProxy
annotation
❖ To enable @AspectJ support with XML-based configuration, use the aop:aspectj-autoproxy
element
SpEL(Spring Expression
Language)
AKHIL K ANIL
SpEL is an expression language supporting the features of querying and
manipulating an object graph at runtime
SpEL API :
● Expression interface
Implementati
● SpelExpression class on of
Expression
● ExpressionParser interface Implementation of
ExpressionParser
● SpelExpressionParser class
● EvaluationContext interface Implementation of
EvaluationContext
● SimpleEvaluationContext class
● StandardEvaluationContext class
Evaluation
ExpressionParser expressionParser = new SpelExpressionParser();
// 1. Literal expression
// 2. Method invocation
// 3. Mathematical operator
// 5. Logical operator
boolVal = expression.getValue(Boolean.class);
// 8. Regex/matches operator
boolVal = expression.getValue(Boolean.class);
Now, we have evaluated the SpEL expression using the default context.
❖ SpEL expressions can be evaluated against a specific object instance, which is
often mentioned as the root object
❖ Define a Bean and use it as the context of the evaluation
@Component(“sampleBean”)
public class SampleBean(){
private String property = “String property“;
private ArrayList<Integer> arrayList = new ArrayList<>();
public SampleBean(){
arrayList.add(15); arrayList.add(16); arrayList.add(17); }
//getters and setters
}
● Create the evaluation context by creating an instance of StandardEvaluationContext
● It takes the root object ( SampleBean in our case) as a parameter in it’s constructor
Example :
The creation of the
ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationCon
text instance is expensive.
// creating evaluation context So, we should cache and
reuse them as much as
SampleBean ctxtBean = new SampleBean(); possible
StandardEvaluationContext testContext = new StandardEvaluationContext(ctxtBean);
// Property value
Expression expression = parser.parseExpression("property");
String strValue = expression.getValue(testContext,String.class);
// compare property
expression = parser.parseExpression("property == 'String property'");
boolean boolVal = expression.getValue(testContext,Boolean.class);
System.out.println(boolVal);
// List value
expression = parser.parseExpression("arrayList[1]");
int val = expression.getValue(testContext,Integer.class);
System.out.println(val);
SpEL in Bean Definition
@Component("user")
public class User {
@Value("598")
private Integer id;
@Value("John")
private String firstName;
@Value("Doe")
private String lastName;
@Value("#{user.firstName.concat(' ').concat(user.lastName)}")
private String fullName;
//getters and setters
}
DATA ACCESS
USING JDBC
AKHIL K ANIL
JDBC abstraction framework packages
All the classes in Spring JDBC are divided into four separate packages
● core — the core functionality of JDBC. Some of the important classes under this package include
JdbcTemplate, SimpleJdbcInsert, SimpleJdbcCall and NamedParameterJdbcTemplate.
● datasource — utility classes to access a data source. It also has various data source
implementations for testing JDBC code outside the Jakarta EE container.
● object — DB access in an object-oriented manner. It allows running queries and returning the
results as a business object. It also maps the query results between the columns and properties of
business objects.
● support — support classes for classes under core and object packages, e.g., provides the
SQLException translation functionality
JDBCTEMPLATE
➔ JdbcTemplate is the classic and most popular Spring JDBC approach. This “lowest-level” approach and all
others use a JdbcTemplate under the covers
➔ NamedParameterJdbcTemplate wraps a JdbcTemplate to provide named parameters instead of the traditional
JDBC ? placeholders. This approach provides better documentation and ease of use when you have
multiple parameters for an SQL statement
➔ JdbcTemplate is the central class in the JDBC core package. It handles the creation and release of
resources, which helps you avoid common errors, such as forgetting to close the connection
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.13</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.8.0</version>
</dependency>
JdbcConfig.java
Querying Examples :
select
1. Number of rows in a relation :
5. Deleting a entry :
It defines only one method mapRow that accepts ResultSet instance and int as the parameter
list
newUser.setUserId(resultSet.getInt(1));
newUser.setFirstName(resultSet.getString(2));
newUser.setLastName(resultSet.getString(3));
newUser.setAge(resultSet.getInt(4));
return newUser;
},userId);
2. Fetching list of domain objects :
String GET_ALL="select * from user_details";
user.setUserId(resultSet.getInt(1));
user.setFirstName(resultSet.getString(2));
user.setLastName(resultSet.getString(3));
user.setAge(resultSet.getInt(4));
return user;
});
Tip for an aspiring developer :
Example :
NamedParameterJdbcTemplate namedParameterJdbcTemplate =
new NamedParameterJdbcTemplate(dataSource);
Example :
public int countOfUsers(User user) {
// notice how the named parameters match the properties of the above 'User'
class
AKHIL K ANIL
SPRING ORM
The Spring Framework supports integration with the Java Persistence API (JPA) and supports native
Hibernate for resource management, data access object (DAO) implementations, and transaction
strategies
● Less coding is required: By the help of Spring framework, you don't need to write extra
codes before and after the actual database logic such as getting the connection, starting
transaction, committing transaction, closing connection etc.
● Easy to test: Spring's IoC approach makes it easy to test the application.
● Better exception handling: Spring framework provides its own API for exception
handling with ORM framework.
● Integrated transaction management: By the help of Spring framework, we can wrap
our mapping code with an explicit template wrapper class or AOP style method interceptor.
Spring-Hibernate Integration
● In hibernate framework, we provide all the database information
hibernate.cfg.xml file
● But if we are going to integrate the hibernate application with spring, we
don't need to create the hibernate.cfg.xml file. We can provide all the
information in the spring.xml file(or by using annotations only)
PROJECT STRUCTURE(ANNOTATIONS ONLY)
Steps :
1. Add dependencies to pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.3.13</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.0.Final</version>
</dependency>
2. Create Config class
3. Create entity class
a. Dao interface
Define methods
● Hibernate
● Toplink
● iBatis
● OpenJPA etc.
Code to persist an object using JPA :
EntityManagerFactory emf =
Persistence.createEntityManagerFactory(String persistence-
unit);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(employee); //persisting employee object
em.getTransaction().commit();
Employee e = em.find(Employee.class, 105); //getting
employee object by id
PROJECT STRUCTURE :
Configuration :
DAO
Implementatio
n
main class
AKHIL K ANIL
OVERVIEW
spring-context
spring-webmvc
jstl
PROJECT
STRUCTURE
1. HibernateConfig.java
2. SpringMVCDispatcherServletInitialize
r.java
3. WebMvcConfig.java
4.
EmployeeController.j
ava
SPRING MVC ANNOTATIONS
❖ @RequestMapping: It is used to map the web requests. It has many optional
elements like consumes, header, method, name, params, path, produces,
and value. We use it with the class as well as the method
❖ @GetMapping: It maps the HTTP GET requests on the specific handler method.
It is used to create a web service endpoint that fetches It is used instead of
using: @RequestMapping(method = RequestMethod.GET)
❖ @PostMapping: It maps the HTTP POST requests on the specific handler
method. It is used to create a web service endpoint that creates It is used
instead of using: @RequestMapping(method = RequestMethod.POST)
❖ @PutMapping: It maps the HTTP PUT requests on the specific handler method.
It is used to create a web service endpoint that creates or updates It is used
instead of using: @RequestMapping(method = RequestMethod.PUT)
❖ @DeleteMapping: It maps the HTTP DELETE requests on the specific
handler method. It is used to create a web service endpoint that deletes a
resource. It is used instead of using: @RequestMapping(method =
RequestMethod.DELETE)
❖ @PatchMapping: It maps the HTTP PATCH requests on the specific
handler method. It is used instead of using: @RequestMapping(method =
RequestMethod.PATCH)
❖ @RequestBody: It is used to bind HTTP request with an object in a method
parameter. Internally it uses HTTP MessageConverters to convert the
body of the request. When we annotate a method parameter with
@RequestBody, the Spring framework binds the incoming HTTP request
body to that parameter.
❖ @PathVariable: It is used to extract the values from the URI. It is most suitable for the RESTful web
service, where the URL contains a path variable. We can define multiple @PathVariable in a method.
❖ @RequestParam: It is used to extract the query parameters form the URL. It is also known as a
query parameter. It is most suitable for web applications. It can specify default values if the query
parameter is not present in the URL.
❖ @RequestHeader: It is used to get the details about the HTTP request headers. We use this
annotation as a method parameter. The optional elements of the annotation are name,
required, value, defaultValue. For each detail in the header, we should specify separate
annotations. We can use it multiple time in a method
❖ @RestController: It can be considered as a combination of @Controller and @ResponseBody
annotations. The @RestController annotation is itself annotated with the @ResponseBody
annotation. It eliminates the need for annotating each method with @ResponseBody.
❖ @RequestAttribute: It binds a method parameter to request attribute. It provides convenient
access to the request attributes from a controller method. With the help of @RequestAttribute
annotation, we can access objects that are populated on the server-side.
AKHIL K ANIL
OVERVIEW
➢ Spring Boot is a project that is built on the top of the Spring Framework
➢ Spring Boot helps you to create stand-alone, production-grade Spring-
based applications that you can run
➢ Spring Boot is a Spring module that provides the RAD (Rapid Application
Development) feature to the Spring framework
➢ It is developed by Pivotal Team and is used to build stand-alone and
production ready spring applications
➢ Latest version : 2.6.1
➢ System requirements : Spring Boot 2.6.1 requires Java 8 and is
compatible up to and including Java 17. Spring Framework 5.3.13 or
above is also required. Maven 3.5+
❖ It is used to create a stand-alone Spring-based application that you can just
run because it needs minimal Spring configuration
● Spring Data: It simplifies data access from the relational and NoSQL
databases.
● Spring Batch: It provides powerful batch processing.
● Spring Security: It is a security framework that provides robust security
to applications.
● Spring Social: It supports integration with social networking like
LinkedIn.
● Spring Integration: It is an implementation of Enterprise Integration
Patterns. It facilitates integration with other enterprise applications using
lightweight messaging and declarative adapters.
ADVANTAGES
Spring Framework is a widely used Java EE Spring Boot Framework is widely used to develop
framework for building applications. REST APIs
It aims to simplify Java EE development that makes It aims to shorten the code length and provide the
developers more productive easiest way to develop Web Applications
The primary feature of the Spring Framework is The primary feature of Spring Boot is
dependency injection. Autoconfiguration. It automatically configures the
classes based on the requirement
It helps to make things simpler by allowing us to It helps to create a stand-alone application with less
develop loosely coupled applications configuration.
To test the Spring project, we need to set up the Spring Boot offers embedded server such as Jetty
server explicitly and Tomcat, etc
Developers manually define dependencies for the Spring Boot comes with the concept of starter in
Spring project in pom.xml. pom.xml file that internally takes care of downloading
the dependencies JARs based on Spring Boot
Requirement.
Spring Boot vs Spring MVC
Spring Boot is a module of Spring for packaging the Spring MVC is a model view controller-based web
Spring-based application with sensible defaults. framework under the Spring framework.
It provides default configurations to build Spring- It provides ready to use features for building a
powered framework. web application
It avoids boilerplate code and wraps dependencies It specifies each dependency separately
together in a single unit
It reduces development time and increases It takes more time to achieve the same
productivity
ARCHITECTURE
Spring Boot follows a layered architecture in which each layer communicates with the
layer directly below or above (hierarchical structure) it.
There are four layers in Spring Boot are as follows:
● Presentation Layer
● Business Layer
● Persistence Layer
● Database Layer
Presentation Layer: The presentation layer handles the HTTP
requests, translates the JSON parameter to object, and
authenticates the request and transfer it to the business layer. In
short, it consists of views i.e., frontend part.
Business Layer: The business layer handles all the business
logic. It consists of service classes and uses services provided by
data access layers. It also performs authorization and validation.
Persistence Layer: The persistence layer contains all the storage
logic and translates business objects from and to database rows.
Database Layer: In the database layer, CRUD (create, retrieve,
update, delete) operations are performed
● Now we have validator classes, view classes, and utility classes.
● Spring Boot uses all the modules of Spring, like Spring MVC, Spring Data,
etc. The architecture of Spring Boot is the same as the architecture of Spring
MVC, except one thing: there is no need for DAO and DAOImpl classes in
Spring boot.
● Creates a data access layer and performs CRUD operation.
● The client makes the HTTP requests (PUT or GET).
● The request goes to the controller, and the controller maps that request and
handles it. After that, it calls the service logic if required.
● In the service layer, all the business logic performs. It performs the logic on
the data that is mapped to JPA with model classes.
● A JSP page is returned to the user if no error occurred.
Spring Initializr
Spring Initializr is a web-based tool provided by the Pivotal Web Service. With the help of Spring
Initializr, we can easily generate the structure of the Spring Boot Project
SPRING BOOT ANNOTATIONS
In addition to the annotations used in Spring Framework Spring boot uses the
following annotations :
@SpringBootApplication=@ComponentScan+@EnableAutoConfiguration+@Configuration
Why SPRING BOOT?
★ Spring Boot manages dependencies and configuration
automatically.
★ We need not to specify the version of the dependencies in our
configuration. Spring Boot manages itself. Spring Boot
upgrades all dependencies automatically in a consistent way
when we update the Spring Boot version
★ Each Spring Boot application includes an embedded server.
Embedded server is embedded as a part of deployable
application. The advantage of embedded server is, we do not
require pre-installed server in the environment. With Spring
Boot, default embedded server is Tomcat
Application properties
starter-parent
❏ The spring-boot-starter-parent is a project starter. It provides default
configurations for our applications. It is used internally by all dependencies.
All Spring Boot projects use spring-boot-starter-parent as a parent in
pom.xml file
starter-web
There are two important features of spring-boot-starter-web:
Starter of Spring web uses Spring MVC, REST and Tomcat as a default embedded
server
Spring Data is a high-level Spring Source project. Its purpose is to unify and easy
access to the different kinds of persistence stores, both relational database
systems, and NoSQL data stores
There are three main features of Spring Data JPA are as follows:
Eg :
{
Spring Data Repository :
Spring Data JPA provides three repositories are as follows:
starter-actuator
It includes a number of additional features that help us to monitor and manage the Spring
Boot application
It contains the actuator endpoints (the place where the resources live). We can use HTTP
and JMX endpoints to manage and monitor the Spring Boot application. If we want to get
production-ready features in an application, we should use the Spring Boot actuator
Spring Boot DevTools
Spring Boot 1.3 provides another module called Spring Boot DevTools. DevTools stands for
Developer Tool
The aim of the module is to try and improve the development time while working with the
Spring Boot application. Spring Boot DevTools pick up the changes and restart the
application
● Property Defaults
● Automatic Restart
● LiveReload
● Remote Debug Tunneling
● Remote Update and Restart
SPRING BOOT HELLO WORLD(REST) - EXAMPLE
No additional dependencies needed
HelloController.java
SPRING BOOT HELLO WORLD(WEB APPLICATION) - EXAMPLE
Additional Dependencies :
To view jsp pages the following dependency is needed
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
● application.properties
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp
Project Structure :
Dependencies needed:
★ spring-boot-starter-data-jpa
★ spring-boot-starter-web
★ mysql-connector-java
★ spring-boot-starter-tomcat
★ tomcat-embed-jasper
★ jstl
application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/productdb-spboot
spring.datasource.username=root
spring.datasource.password =root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.show-sql=true
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
QUERY METHODS
● The JPA module supports defining a query manually as a String or having it being
derived from the method name
● you can either use JPA named queries through a naming convention (
Using JPA Named Queries) or rather annotate your query method with @Query
this translates into the following query: select u from User u where u.emailAddress = ?
1 and u.lastname = ?2
THE END
AKHIL K ANIL