0% found this document useful (0 votes)
4 views

JAVA FULL STACK DEVELOPMENT

Uploaded by

medamkowsik2004
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

JAVA FULL STACK DEVELOPMENT

Uploaded by

medamkowsik2004
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 26

JAVA FULL STACK

DEVELOPMENT
CO-1
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------

HIBERNATE
----------
1)Introduction
2)Why Hibernate
3)Advantages of Hibernate
4)Architecture
5)POJO Class
6)Mapping File (xml file)
7)Configuration File (xml file)
8)Hibernate Examples (CRUD Operations)
9)Hibernate Query Language (HQL)
10)Hibernate Criteria Query Language
11)Inheritance Mapping

1) Introduction :
----------------------
Hibernate is a Java program developed by Gavin King
It is a Framework which simplifies the development of java application to interact
with a database
It is an Open Source, light weight and works based on ORM Tool
- ORM Tool:
Object Relational Mapping
ORM is a technique for converting data b/w Java objects & Relational
Databases (Tables)
ORM implements the responsibility of mapping java object to Relational
database

JAVA Application--------ORM(Hibernate)--------Database

Some pf the popular ORM tools are :

hibernate
hyBetis
myBetis
TopLik,etc

2) Why Hibernate
-----------------------
Simplifies database interaction
Cross Database portability

3) Advantages of Hibernate
----------------------------
- Open source & Light weight
- Fast Performance
- Database independent query
- Auto table creation
- Exception Handling
4) Hibernate Architecture
---------------------------
Hibernate Architecture consists of 3 layers
Application Layer - java application
Hibernate Layer - mapping & configuration
Database Layer - Oracle, MySQL
Refer to Diagram

It consists of Pre defined java objects / interfaces such as


SessionFactory, ConfigurationFactory, TransactionFactory

5)POJO Class
--------------
POJO stands for Plain Old Java Object
POJO is nothing but a Java Bean
Hibernate allows only POJO classes
POJO class consists only Setters & Getters

Example:
--------

Class Employee{
private int eid;
private String ename;

-> 1 setter and 1 getter method for eid


1 setter and 1 getter method for ename

getEid(){
}
setEid(){
}
getEname(){
}
setEname(){
}

Configuration File:
--------------------
- The purpose of configuration file is to define the properties of database.
- Configuration file can be defined in 2 ways.
- It will be either in xml or using annotations (xml)
- The Configuration file has to be denoted by hibernate.cfg.xml (save)
- Configuration file is loaded into hibernate application
- The configuration file must contain following information
- Connection properties
- Hibernate properties
- mapping file resources

Note:
Number of configuration = No of databases

Syntax:
hibernate.cfg.xml
-----------------
<hibernate-configuration>
<session-factory>
<!connection properies>
<property name="connection.driver_class">Load Drivers</property>
<property name="connection.url">Connection URL</property>
<property name="connection.username">Username</property>
<property name="connection.password">Password</property>

<!hibernate properties>
<property name="show_sql">true/false</property>
<property name="dialect">database name</property>
<property name="hbm2ddl.auto">create</property>

<!mapping file>
<mapping resource="filename(mapping)"/>
<mapping resource="filename(mapping)"/>
<mapping resource="filename(mapping)"/>
</session-factory>
</hibernate-configuration>

Example: Oracle

<hibernate-configuration>
<session-factory>
<!connection properies>
<property
name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property
name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="connection.username">system</property>
<property name="connection.password">admin</property>

<!hibernate properties>
<property name="show_sql">true</property>
<property name="dialect">oracle</property>
<property name="hbm2ddl.auto">create</property>

<!mapping file>
<mapping resource="employee1.hbm.xml"/>
<mapping resource="employee2.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Example: MySQL

<hibernate-configuration>
<!connection properies>
<property
name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property
name="connection.url">jdbc:mysql://localhost:3306/</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>

<!hibernate properties>
<property name="show_sql">true</property>
<property name="dialect">mysql</property>
<property name="hbm2ddl.auto">create</property>

<!mapping file>
<mapping resource="employee1.hbm.xml"/>
<mapping resource="employee2.hbm.xml"/>
</hibernate-configuration>

Mapping File:
--------------
- It is a part of Hibernate Application
- Mapping file will be denoted either in xml
- Mapping file will be implemented either in xml or annotations (xml recommended)
Every Orm is a
-It is a mechanism of placing object properties (java object) to the specific
column of a table (DB)
- This mapping file contains how a mapping can be done from a POJO class to db name
and from class properties to column names
POJO class -> table name
prop1 -> column1
prop2 -> column2

- While creating mapping file, we can create one or multiple no. of mapping files
based on application requirement
Note:
java Object -> table

Every object will have the following properties


a. Identity (Object name)
b. State (Object value)
c. Behaviour (Object method)

Syntax: filename.hbm.xml
------------------
<hibernate-mapping>
<class name="POJO class name" table="table name in DB"/>
<id name="class-property" column="col name in table"/>
<property name="class-property" column="col name in table"/>

</hibernate-mapping>

Example: employee.hbm.xml
------------------
<hibernate-mapping>
<class name="Employee" table="emp"/>
<id name="eid" column="tid"/>
<property name="ename" column="tname"/>

</hibernate-mapping>

- table is created by user with table name as emp and col names as tid and
tname
Note: Significance of Hibernate
(Table MUST be created automatically)

Syntax: filename.hbm.xml
------------------
<hibernate-mapping>
<class name="POJO class name"/>
<id name="class-property"/>
<property name="class-property"/>
</hibernate-mapping>
Example : employee1.hbm.xml
------------------
<hibernate-mapping>
<class name="Employee"/>
<id name="eid"/>
<property name="ename"/>

</hibernate-mapping>

- table will be created automatically by Hibernate framework with table name


as employee and column name as eid and ename

Hibernate Example: (CRUD Operations)


-------------------------------------
- Every Hibernate Application MUST have the following 4 files
a. POJO class (.java)
b. configuration file (hibernate.cfg.xml)
c. mapping file (filename.hbm.xml)
d. logic file (.java)(main method)(execute)

- Skeleton of hibernate Application

Step-1: Create a maven project


-> maven-archetype-quickstart
Step-2: pom.xml
-> Compiler properties 1.7 to 1.8
-> dependencies
- Hibernate Core
- Hibernate Entity Manager
- MySQL
- Oracle
Step-3: Update your maven project
Step-4: You need to create a new folder naming as resources (config file and
mapping file)

->src -> main -> right click


->new
->folder
(resources)
Step-5: Implement Hibernate Concepts
- POJO Class (src/main)
(filename.java)
- Configuration file (src/main/resources)
(hibernate.cfg.xml)
- Mapping File (src/main/resources)
(filename.hbm.xml)
- logic file (src/main/java)
(filename.java)
Step-6: Run Logic File
-> Right Click
-> run as
-> java application

Example-1: Hibernate Example (Insert)

HQL :-
---

- HQL stands for Hibernate query language


- HQL is database independent query language
- HQL is same as SQL, but the only difference is SQL depends on table where as HQL
depends on POJO class
- To work with HQL we need use Query interface

Query Interface :-
-------------

- it is an object oriented representation of Hibernate Query


- the object of a query interface can be obtained by calling create query method
through the session object

Query q = s.createQuery("HQL Query");

- The methods of query interface are


- a. execteUpdate()
- b. list()
- c. setFirstResult()
- d. setMaxResults()
- e. setParameter()

Example - 1 :-
-------

HQL Example
(To retrieve all the records)

Configuration cfg = new Configuration();


cfg.configure("hibernate.cfg.xml");

SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();

Transaction t = s.beginTransaction();

Query q = s.createQuery("from employ");

List<employee> l = q.list();

for(employee X:l)

System.out.println(X.getEname());

}
}
}

-> output : names of all employees

Example -2 :- HQLRetItr:-
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");

SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();

Transaction t = s.beginTransaction();

Query q = s.createQuery("from employee");

List<employee> l = q.list();

Iterator<employee> i = l.iterator();

while(i.hasNext()) {
employee e = i.next();
System.out.println(e.getEsal());

Exapmle-3 :- HQL example(to ret specific range of records-it is known as


pagination)

note:- ex-1,2 are to ret all records from table


ex-3 to ret specific range of records(starting record to how many
no.of records)

Configuration cfg = new Configuration();


cfg.configure("hibernate.cfg.xml");

SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();

Transaction t = s.beginTransaction();

Query q = s.createQuery("from employee");

q.setFirstResult(5);
q.setMaxResult(15);

List<employee> l = q.list();

Iterator<employee> i = l.iterator();

while(i.hasNext()) {
employee e = i.next();
System.out.println(e.getEsal());

Example-3:-
---------
Example-4:-
---------

HQL Example(to update the record)

HQL-> update

query-> update employee set ename=:n where eid=:i

q.setParameter(n,"XYZ");
q.setparameter(i,111);

Example-5:-
-------

Hql Example(to delete a record)

Query->delete from employee where id="1"

Example-6:
------

Hql Example(to insert a record)

Query->insert into employee(eid,ename,esal)values(4,'abhinay',2345")

Example-7:-
------
Hql Example(retrieve all records with partial no.of columns)

Query q = s.createQuery("eid ename from employee")


List<Employee> l = q.list();

Iterator i = l.iterator();
while(i.hasNext()){
Object ob[] = (object[])i.next();
System.out.println(ob[0]+" " + ob[1]);
Example-8:-
-------
HQL example(to retrieve all records with single column)

Query q = s.createQuery("eid from employee")


List<Employee> l = q.list();

Iterator i = l.iterator();
while(i.hasNext()){
Object ob = (object)i.next();
System.out.println(ob);

Example-9:-
--------

HCQL
-----
- Hibernate Criteria Query Language
- Using HCQL I can retrieve records with all the records at a time
- In order to implement HCQL in hibernate application, I need to use criteria
interface
Criteria Interface:
Criteria interface object can be obtained by calling createCriteria()
method to a session object

Criteria cr = s.createCriteria();

- The methods of Criteria interface are


a. add()
b. addOrder()
c. setFirstResult()
d. setMaxResults()
e. setParameter()

Restriction Class
------------------
this is a class which consists of many methods
to add restriction/condition/criteria on HQL query
- The methods of Restrictions class are
a.lt()
b.le()
c.gt()
d.ge()
e.eq()
f.ne()
Order Class
------------
- This calss consists of many methods
- In order to retreive or display data from db tabe either in ascending or
descending order
- The methods are
a. asc()
b. des()
Example 1 : HCQL Example

Inheritance Mapping:
---------------------

Inheritance:
-------------
- Aquire the properties from Base Class to Derived Class refers to Inheritance
- Inheritances are 5 types (OOP)
1. Single Inheritance
A
|
|
B
2. Multiple Inheritance
A B C
| | |
| | |
-----------------
|
|
D

3. Multi level Inheritance


A
|
|
B
|
|
C

4. Hierarchial Inheritance
A
|
|
-----------------
| | |
| | |
B C D

5. Hybrid Inheritance
- Combination of Multiple Inheritance + Hierarchial Inheritance
A
|
|
-----------------
| | |
| | |
B C D
| | |
| | |
-----------------
|
|
E
Note :
Java doesn't support Multiple Inheritance

Mapping:
- Mapping refers to the relationship between different tables in your Database
- Different types of mappings are
1. IS-A (Inheritance)
2. HAS-A (Association)

- Inheritance Mapping can be implemented in 3 ways in Hibernate Application


1. Table per Class
2. Table per Sub-Class
3. Table per Concrete-Class

Scenario:
Payment Person
| |
| -------------------------
---------------- | |
| | Student Employee
Card Cheque

1. Table Per Class


Payment Person

2. Table Per Sub-Class


Card, Cheque Student, Employee

3. Table Per Concrete Class


Payment, Card, Cheque Person, Student, Employee

1. Table Per Class:

POJO Class:
--------------
class Payment{
int pid;
double pamount;

-> generate getters & setters


}

Class Card{
String cardType;

-> generate getters & setters


}

class Cheque{
String chequeType;

-> generate getters & setters


}

Configuration File:
---------------------

Mapping File (payment.hbm.xml)


---------------------------------
<hibernate-mapping>
<class name="com.klu.JFSDS25_IMTC.Payment" >

<id name = "pid"/>


<property name="pamount" />
<discriminator column=""/>
<subclass name = "com.klu.JFSDS25_IMTC.Card" discriminator-value="c">

<property name="cardType"/>
</subclass>

<subclass name = "com.klu.JFSDS25_IMTC.Cheque" discriminator-value="cq">


<property name="chequeType"/>
</subclass>

</class>
</hibernate-mapping>

Logic File (TablePerClass)


---------------------------

class TablePerClass{

Transaction t = s.beginTransaction();

Card c = new Card();


Cheque cq = new Cheque();

c.setPid(101);
c.setPamount(1,45,000);
c.setCardType("Credit Card");

cq.setPid(201);
c.setPamount(1,40,000);
c.setChequeType("RTGS");

s.save(c);
s.save(cq);

t.commit();

s.close();
sf.close();

DB:
Payment
pid pamount cardType ChequeType
101 1,45,000 Credit

Example-2 : TablePerSubclass

POJO Class:
------------
same as previous
Configuration File
-------------------

<hibernate-mapping>
<class name="com.klu.JFSDS25_IMTC.Payment" >

<id name = "pid"/>


<property name="pamount" />

<Joinedclass name = "com.klu.JFSDS25_IMTC.Card" discriminator-value="c">


<property name="cardType"/>
</Joinedclass>

<Joinedclass name = "com.klu.JFSDS25_IMTC.Cheque" discriminator-value="cq">


<property name="chequeType"/>
</Joinedclass>

</class>
</hibernate-mapping>

Logic File
-------------
same as previous

DB -> Table Per Subclass

Card Cheque
pid pamount cardType pid pamount chequeType
101 1,45,000 Credit 201 1,40,000 RTGS

3.

Mapping
--------

<hibernate-mapping>
<class name="com.klu.JFSDS25_IMTC.Payment" >

<id name = "pid"/>


<property name="pamount" />

<unionclass name = "com.klu.JFSDS25_IMTC.Card" discriminator="c">


<property name="cardType"/>
</unionclass>

<unionclass name = "com.klu.JFSDS25_IMTC.Cheque" discriminator="cq">


<property name="chequeType"/>
</unionclass>

</class>
</hibernate-mapping>

Logic
------
same
DB -> Table per Concrete Class

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
CO - 2
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------

1) Introduction
2) Why Spring
3) Advantages of Spring
4) Spring architecture
5) Dependency Injection (DI)
6) Inversion of control (IOC)
7) Primitive and non Primitive datatypes
8) Spring DAO ( Data Access Objects) using JDBC
9) Spring DAO ( Data Access Objects) using Hibernate
10) Spring MVC using hibernate

Introduction:
--------------
- Spring is a java framework which was developed by Roe Johnson
- This framework is used to build Java application at Enterprise level(We can
build console apps and applications and web application, This framework, This
framework provides that the user is able to interact with console and web
application)
- It is light weight Framework i.e., Application design using spring frame work
execute faster.
- The core principle is to simplify the java development process and promote good
design practices

Spring Framework consists of several modules such as


- IOC (Inversion of control), DAO (Data access objects), ORM, Web MVC, etc..

Why Spring?
--------------
- Using Hibernate , we can build only console applications whereas using Spring
framework, we can able to build applications console to web
- Hibernate is a ORM Framework primarily focussed on Data Persistence where as
Spring is a comprehensive framework that provides wide array of features
- Spring can be used with various ORM Frameworks including Hibernate ( Spring is
called as Master Framework / Mother Framework )

Advantages of Spring
---------------------
- Lightweight
- Fast Performance
- Eay to test and maintain
- Allows Loosely Coupled
- It provides pre defined templates

Spring Architecture
---------------------
- Spring Architecture consists of several modules such as IOC,DAO,ORM,Web MVC,
AOP,etc.
- All these modules are grouped into Test , Spring Core Container, DAO, Web MVC
( Refer to diagram - internet )

Configuration file (applicationContext.xml)


--------------------------------------------

Logic File (Test.java)


-----------------------

class Test{
public static void main(String[] args){

ApplicationContext ac = new
ClassPathXmlApplicationContext("applicationContext.xml");

EmployeeDAO dao = (EmployeeDAO)ac.getBean("empdao");


Employee e = new Employee();
e.setId(111);
e.setEname("ABC");
e.setEsal(50000);

dao.insertEmployee(e);

}
}

Spring MVC Architecture


-------------------------
- MVC stands for Model, View, Controller

Model - Business Logic / Application Data / Code


(Back End)
View - Presentation Logic / User Interface
(Front End)
Controller - Interface between Model & View / Interface between Business &
Presentation Logic / Interface between Front end and Back end

- MVC is one of the popular and standard design pattern / architecture which will
be used by most of the developers to build web application
- Spring MVC is a java framework which is used to design web applications
- Spring MVC includes all the basic core components of Spring like DI ( Dependency
Injection ) & IOC ( Inversion of Control )
- Spring framework provides ans elegant solution to build web application following
MVC architechture using DispatcherServlet (Class name)
- DispatcherServlet is a class in spring framework that receives an http request
and maps the right resources such as model, view, and controller
- The architechture of Spring MVC is

Refer to Internet
Steps involved in Spring MVC
1. Http Request
2. Dispatcher Servlet
3. Handler Mapping
4. Controller (model and View)
5. ViewResolver
6. View (Http Response)

Explanation:
- This architecture follows sequence of events corresponding to an incominbg
HttpRequest to dispatcher servlet
- After Receiving HttpRequest, dispatcherServet consults handlermapping to
call the appropriate controller
- The controller will take the request and call the appropriaaaaate servic3
method uwing GET and POST
- Then DispatcehrSevlet will ake the help of ViewResolver to pick up a right
view based on httpRequest
- Finally, the viewnwhich got picked by ViewResolver will be HttpResponse

Web Application
(Bus Reservation System)

Http Request
HttpRequest
(Httpe://www.abhibus.com) ---------------->
Web Page
(Abhi
Bus)
(Web Server)
(AWS)

Advantages of Spring MVC


--------------------------
1. Light Weight
2. Rapid Development
3. Separate Roles
4. Reusability Code
5. Easy to Test

Example: Spring WEB-MVC


Step -1: Maven Project
archetype - webapp (1.4)
Step -2: a. update maven compiler (1.7 to 1.8)
b. Add Dependencies
Step -3: Update the Maven Project
Step -4: Resource directory
(config files and mapping files)
src/ main/
Step -5: Implementation of Spring WEB-MVC
(DispatcherServlet)
(ViewResolver)
Step -6: Need to have server
(Apache Tomcat 8.0 or 9.0)
Step -7: Run this application ( run as -> server )
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

REACT

Introduction
Why React
Adv of React
Features of React
Pro and Cons of React
React js vs angular js
React Native vs React js
React JSX
React Components ***
React State
React props
React props validation
React state vs props
React Constructor
React Components API
React Components Lifecyle
React Forms
Conditional Rendering
React Lists
React Keys
React Fragments
React Router
React CSS
React Map
React Table
React Animation
React Higher Order Components
React Code Splitting
React Context
React Hooks
React Flux
React Redux
React Axios
React Portal

Introduction:
-------------

React is a declarative,efficient,flexible java script library


It is Open source
Responsible for only View
The main objective of react is to develop the user interface to improve speed of
applications
Designed by Facebook

Note: React is also called as framework which helps to build UI

Why React
----------
To develop UI to increase speed of application
Using React, and application can be splitted into several components
The Flow of Data in React is Uni Directional

Advantages of React:
--------------------
Virual DOM
Faster Rendering
Reusable
Cross Platform Development
Search Engine Optimization

Features of React:
-------------------

JSX
Component based Architecture
One way Data Binding
Application Performance
Dynamic Routing ( Static vs Dynamic Routing )

Pros & Cons:


-------------

@imasheshk (https://t.me/imasheshk)

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
CO3 - SPRING BOOT

Introduction
Why SpringBoot
Features of Spring Boot
Advantages of Spring Boot
Spring Boot Architecture
Working with Spring Boot (3 ways)
Spring Initializr
SAS Tool (IDE)
CLI (Command Line interface)
Spring Boot examples (SI)
Thymeleaf and views(html/jsp) rendering
Spring Starters (web)
Spring Boot web MVC(CRUD)
Spring Boot Security
Note : Spring Boot -> No configuration files
Default server--

INTRODUCTION
-------------
Spring Boot is a Spring Module which provides rapid development
It is used to create spring based applications with minimal configuration
Spring Boot is a combination of Spring & HTTP services (GET, POST, PUT, DELETE)
Latest version of spring Boot is 5.x
Developed by Dave Syer
Spring Boot is a java framework which is used to build applications(web) .
It provides an easier and faster way to setup configuration and run both simple
and web application
Why Spring Boot:--
It reduces the development time & cost
It provides powerful database transaction management
It simplifies the integration of other java frameworks like hibernate , Spring,
filters, struts etc
Features of Spring Boot:------
Data access is easy
Testing automatically
Auto Configuration
Spring Boot starters (Web)
Embedded servers
Security
--
Spring Boot Initializr
Advantages of Spring Boot:
It offers a lot of plugins--
It offers CLI (command line interface) for developing and testing Spring Boot
Application
It increases the productivity as it decreases the development time
Spring Boot Architecture:--
1.
It represents View or User Interface
Consists of 4 layers
Each layer with have a communication or interaction with other layers in both ways
The layers are :
Presentation Layer:
Presentation Layer------------->(Bidirectional)
Business Layer------------->(Bidirectional)
Persistence layer------------->(Bidirectional)
Database Layer
It handles the HTTP request received from the user and transfers the same to
business logic
2.
It handles the Business Logic of your application
3.
It handles the storage logic
4.--
Business Layer:
Persistence Layer:
Database Layer:
It handles the database and performs crud operations
Working with Spring Boot:
We can start working with SB using 3 different ways

1 Spring Initializr(recommended)
2 STS Tool (Spring Tool Suite - IDE)
3 CLI

1. Spring Initializr :
---------------------------
1. Open https://start.spring.io/
2. project --> maven
3. Language --> Java
4. Spring BooT --> 3.2.10
5. Project Metadata
Group
Artifact
Name
6. Dependencies
--> Spring Web
--> Spring Security
--> Spring Boot DEV Tools
--> Thymeleaf
7. Generate --> Project will be downloaded which is Boiler Plate Code

Spring Boot Example:


Example 1:
Simple eg to display message on Console
Example 2:
Simple eg to display message on Browser

Note:
To return a String on Browser Controller must be annotated with @RestController

ThymeLeaf & Views Rendering


-----------------------------

Here we will understand how to render a view

To render a View (html file)

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class Controller2 {

@GetMapping("index")
public String method2() {
return "index";
}
}

To render a View , the class must be annotated with @Controller

HTML Files must be placed only in templates if u use ThymeLeaf

Note:
------
Spring Boot Application / Project Components
----------------------------------------------

1. application properties
- It is a component which defines all the properties of a SpringBoot
Application
- src/main/resources
application.properties
Ex: spring.application.name = projectname

server.port = 2004

spring.mvc.view.prefix = /views/
spring.mvc.view.suffix = .jsp

2. Annotations
- Annotation is a form of data about application , every application
represents some form of data

a. Spring Core Annotations


b. Spring Boot Annotations

a. Spring Core Annotations

i. @Required
- This is method level annotation
- This annotation is used for method which is mandatory to
execute
ii. @ComponentScan
- This is class level annotation
- It is used to scan a package for beans
iii. @Bean
- This is method level annotation
- It is infact an alternative to XML file
- It tells the method to produce a bean managed by Spring
container
iv. @Component
- It is a class level annotation
- It is used to make a java class as a bean
v. @Service
- This is a class level annotation
- It is used for a class where the business logic of the
application is defined
vi. @Repository
- This is class level annotation
- It is used for a class where DAO implements

b. Spring Boot Annotations

i. @SpringBootApplication
- This is class level annotation
- The purpose is, it defines starting point of your application
- This annotation is a combination of 3 annotations
a. @EnableAutoConfiguration
b. @ComponentScane
c. @Configuration
ii. @RestController
- This is class level annotation
- It is used to implement REST Services
iii. @RequestMapping
- This is method level annotation
- It is used for any kind of HTTP request
iv. @GetMapping
- This is method level annotation
- It maps an HTTP GET request
v. @PostMapping
- This is method level annotation
- It maps an HTTP POST request
vi. @PutMapping
- This is method level annotation
- It maps an HTTP PUT request
vii. @DeleteMapping
- This is method level annotation
- It maps an HTTP DELETE request
viii. @Controller
- This is class level annotation
- It is used for class where the methods are defined to render
view

3. Dependencies Management
- It manages all the dependencies for maven project ( using SI )
- The Dependencies will be managed in pom.xml file
4. Webapp
- It manages all the views to be rendered
- It must be created by developer
5. Spring Starters
- It will be discussed as our next topic

Example - 5:
Render a form using JSP
application.properties

Example - 6:
Render a form and When you click on Submit button display message on brows as
"Details Submitted Successfully"

Example - 7:
Render a form & when you click on Submit button display the details entered
in the form on a webpage4

Example - 8:
Provide the pathname in url & display the same on webpage
O/P:
Name:
Mobile:

9. Spring Starters
--------------------
- It is a collection of dependencies which simplifies the development process
of springboot application
- The different Spring Starters are
1. Spring Web
2. Spring Parent
3. Spring Actuator
4. Spring Test
5. Spring JPA
6. Spring Security
7. Spring Thymeleaf
8. Spring DevTools , etc

1. Spring Web:
----------------
- To act as a Web Application

2. Sprig Starter Parent :


------------------------
- It is used in Maven Project to simplify Dependency management and configuration
for spring applications
- It acts as Project Object Model (POM) that manages the versions of dependencies
and plugins to support your application

3. Spring Starter Actuator:


----------------------------
- This Starter provides production ready features for monitoring and managing the
application ( Ex: Health Check )

4. Spring Starter Test:


-----------------------
- This starter provides set of Testing Tools to test Spring Boot Application
- JUnit

5. Spring Starter Thymeleaf:


----------------------------
- This starter integrates Thymeleaf engine with Spring Boot allowing you to create
Dynamic Web Application

6. Spring Starter DevTools:


---------------------------
- It is a starter that enchances the development experiences in Spring Boot
Applications by providing features like automatic restart, live reload, debugging,
etc

7. Spring Starter Security:


---------------------------
- This starter provides Security to your Spring Boot Application providing
authentication and authorization as the key features

8. Spring Starter JPA:


----------------------
- It is a dependency which provides Database access via an object

Ex: Spring Boot Application to interact with Database (MySQL) using


CommandLineRender & EntityManager

1. Open Spring Initializr


2. Add Dependencies
- DevTools
- JPA
- MySQL
3. Generte -> Extract > Import Eclipse

4
5. application.properties

server.port=2004

spring.datasource.url = jdbc:mysql://localhost:3306/klu
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.ddl-auto = update

6. Entity Class

Class Employee{
@Id
private int eid;
private String ename;
private double esal;

-> Setters & Getters


}
7. Create an interface

public interface EmployeeDAO {


public void insertEmployee(Employee employee);
}

8. Implementation Class

public class EmployeeDAOClass implements EmployeeDAO{

EntityManager em;

@Override
public void insertEmployee(Employee employee) {
em.persist(employee);
}

9. Load the Object using CommandLineRunner

public class EmployeeLoad implements CommandLineRunner{

EmployeeDAO edao;

public EmployeeLoad(EmployeeDAO edao) {


this.edao = edao;
}

@Override
public void run(String... args) throws Exception {
Employee e = new Employee();
e.setEid(111);
e.setEname("Kowsik");
e.setEsal(50000);

edao.insertEmployee(e);

}
}

10. Run this File

Spring Boot Security

- JFSDS25-SBS

sr/main/java
com.klu
ControllerSecurity

public class ControllerSecurity{


@GetMapping("/home")
public String method1{
return "Welcome to SBS";
}
}

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
CO 4
------------------
------
Spring Cloud and Microservices

Introduction
Why Spring Cloud
Features of Spring Cloud
Advantages of Spring Cloud
Architecture
Spring Cloud Components
Main Projects of Spring Cloud
Spring Boot vs Spring Cloud *

Microservices
--------------
Introductiion
Why Micro Services
Features
Advantages of micro Services
Architecture
Creating a simple microservice
Working with microservices

What is Spring Cloud


Spring Cloud is a framework for building Cloud Applicaions
Spring Cloud is also developed by Deve syer
Why Spring Cloud
-----------------
The purpose is to simplify the implementation in spring cloud

Features:
---------
To build Cloud Applicaiton
Centralization

You might also like