Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
249 views
14 pages
SpringBOOT PDF
Uploaded by
AKSHAY ANDURE
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save SpringBOOT.pdf For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
249 views
14 pages
SpringBOOT PDF
Uploaded by
AKSHAY ANDURE
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save SpringBOOT.pdf For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save SpringBOOT.pdf For Later
You are on page 1
/ 14
Search
Fullscreen
Introduction to Spring Boot What is Spring Boot Ovsecr Spring Boot is basically an extension of the Spring framework Spring Boot Framework is not implemented from the scratch by The Spring Team, It eliminated the boilerplate configurations and some tedious development steps required for setting up a Spring application. Spring Boot uses completely new development model to make Java Development very easy Embedded HTTP XML cbean> Spring Boot Spring Framework Servers Configuration or (Tomcat, Jetty) @ Configuration Problems with spring framework (orem = The core feature of Spring framework is dependency injection. Spring alsoe provides great integration with other frameworks, like Hibernate. Spring provides a few frameworks of its own - for example, Spring MVC for developing web applications and REST API. If you look at any Spring-based application, such as a Spring MVC application, many configurations in xml file. work.web. Serviet.view.InternalResourceViewRe: jews/ amen" suFFix">
Problems with spring framework Ossecr = Configuring DispatcherServiet in deplyment descriptor = Configuring data-source as well as transaction manager "org. springfranework. orn. pa. LocalContatnerEntityanagerFacts titynanagerFactory"> rsistenceunithane” values"hsgl_pu” /> source’ referdatasource® /> efetentitymanagervactory= datasource™ /> rty nanes"dataseurce’ refs n- driven transaction-managers" transact ionkanager Features of Spring Boot Oxvecr = Itis very easy to develop Spring Based applications with Java or Groovy(language). It reduces lots of development time and increases productivity. It avoids writing lots of boilerplate Code, Annotations and XML Configuration. Itis very easy to integrate Spring Boot Application with its Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security ete. It follows “Opinionated Defaults Configuration” Approach to reduce Developer effort. It provides Embedded HTTP servers like Tomcat, Jetty etc. to develop and test our web applications very easily. It provides lots of plugins to develop and test Spring Boot Applications very easily using Build Tools like Maven and Gradle It provides lots of plugins to work with embedded and in-memory Databases very easily.Advantage (o)7)20 = Inreal-time spring applications we need writing many XML configurations, server setting, adding dependencies...etc. But with spring Boot we can avoid all these boilerplate code, writing XML configurations and annotations. Spring Boot comes with inbuilt server, we no longer have to use any external servers like Tomcat, Glass-fish or anything else, so don’t need to deploy WAR files The intelligent auto-configuration attempts to auto-configure your application based on what dependencies you added. It is contextually aware and smart. Spring Boot provides starter dependencies which can be used to manage dependencies for jar files. spring-boot-starter-web can be used for developing web application. It avoids writing multiple dependencies. Goals of Spring Boot [ora = To avoid XML Configuration completely = To avoid defining more Annotation Configuration(It combined some existing Spring Framework Annotations to a simple and single Annotation) To avoid writing lots of import statements To provide some defaults to quick start new projects within no time. = To provide Opinionated Development approach. The disadvantages... Osvecr = The main disadvantage is, it will be little tough to migrate existing spring enterprise applications to Spring Boot. Large deployment files that result from unused dependencies Its inability to build large, monolithic applications (although it works extremely well for developing microservices)Tien) clea) ol (ol 01g = Let us learn Spring Boot Hello World application using Eclipse and Maven. Steps to be followed are : 1. Create File > New > Maven Project 2 Select ‘create a simple project’ checkbox and check default workspace location for storing the project 3. In this window provide Group ID(it’s a package name) and Artifact ID(Project Name) and click on Finish button a Amaven project gets created in your workspace with the following structure 4 3 SpringBootHelloWorld & stc/mainjave rc/main/resources @ sic/testjova ® src/test/resources Ba JRE System Library (125E-1.5} & sc © target BB pomam! Talento (oem = Please Note : We are going to change Java version little later 5. Now we will add Spring Boot related stuff in pom.xml = Add spring-boot-starter-parent in pom.xml Td>com. object< >SpringBoo! 0. 1-SNAPSHOT< >first simple demo >org.springframework.boot Id>spring-boot-starter-parent: 1.5.6, RELEASE< >Simple Example Ovsect + Spring-boot-starter-parent is an existing project given by spring team which contains Spring Boot supporting configuration data + It will not download any jar files *
tag in pom.xml allows to manage the following things for multiple child projects and modules: ‘+ Configuration - Java Version and Other Properties ‘+ Depedency Management - Version of dependencies ‘+ Default Plugin Configuration 6. Create a simple bean class annotated with @Component @component public class Test { public string tostring() t return "String reprenetation of Test bean"; ) ? 7. Write following code for finding list of beans that get created @springBootApplication ublic class SimplespringBootApplication ( Pee ijublic seatic void main(sering{] exge) { ApplicationContext ctx = SpringApplication.run (SimplespringBootApplication.class, args); /#test t = ctx.getBean (Test .class! System. cut.printin(t.tostring() 7 String [] beans = ctx.getBeanDefinitionNames (); for (String beanName : beans) System. out.printIn (beanName) ; @SpringBootApplication annotation, means this is the starting point for our Spring Boot application 8. Add java version in properties element 9. Right click on the application > Maven > Update Project. Observe the directory structure of the project; It will create maven dependencies folder which will include all the supporting jar files and java version even will be modified to 1. 10. Finally, right click on the application > Run As > Java ApplicationSimple example for web developme = Inthe dependencies, add spring-boot-starter-web for web module. >org.springframework.boot< s>spring-boot-starter-web { //save, fetch, update, delete Steps for developing REST API Ossecr = Step 5: Creating Service Classes = Service classes will encapsulate business logic like performaing some calculations, filtering the records etc which will take the help of repository to deal with the database. import com.example.demo.entities.contact; import com.example.demo.repositories.ContactRepository; @service public class ContactService { Gautowized ContactRepository crepo; public List
getall () t return crepo.findAll (); = Step 6: Creating a Controller = Controller classes are used for accepting the request and providing the request processing logic.Steps for developing REST API Ossecr = Controller class is annotated with @RestController, which tells Spring Boot to consider this class as REST controller and register @RequestMapping paths inside it to respond to the HTTP requests. _ Ghe: rolle: public class ContactController { @autowired ContactService cservice; @cettapping("/allcons") public List
getall() { return ceervice.getall (); } = Step 7: Compile, Build and Run 8080 is the default port that Spring Boot runs in. To run the application, run the application as java application. Check messages with console. Steps for developing REST API Ossecr = Step 8: Testing the Spring Boot REST APIs = Spring Boot REST API is now up and running on http://localhost:8080/. = Tosend an HTTP GET request, go to http://localhost:8080/getAll from your browser or using postman tool and check the response received in the form of JSON. “name” :"Jane”@Componentscan annotation (oT 01g = Right now RestController is created in the same package as that of Main Application = So Spring boot will automatically scan all the components under that package at the time of starting the application = If we create RestController in different package, we need to tell Spring Boot to scan this component explicitly otherwise application will generate 404 error = Add @Componentscan annotation for the main class public a! pplication { public static void main(String{] args) ( SpeingApplication.run(Application.class, « ’ Customized methods in repository (ol 701g = Rules to define customized query methods in repository. = Rule 1—The name of the query method must start with findBy or getBy or queryBy or countBy or readBy prefix. The findBy is mostly used by the developer. for example. * public List
findByName(String name); * Note: name is the name of the property in entity class Rule 2 — The first character of field name should capital letter. Although if we write the first character of the field in small then it will work but we should use camelcase for the method name. * public List
findByname(String name); // valid but should be avoided Rule 3 — While using findBy or getBy or queryBy or countBy or readBy the character B must be in capital letter, else we will get an exception while deployment. -* public List
findbyName(String name); //invalidCustomized methods in repository Olam = Rules 4—We can write the query method using multiple fields using predefined keywords(eg. And, Or etc) but these keywords are case sensitive. We must use “And” instead of “and”. + public List
findByNameAndRollNumber(String name, String roliNumber); //valid + public List
findByNameandRollNumber(String name, String roliNumber); //invalid Rule 5 — We can write the query method if we want to restrict the number of records by directly providing the number as the digit in method name. We need to add the First or the Top keyword before the by and after find. for example : * public List
findFirst3ByName(String name); Using @Query annotation O/T Lom = Writing JPQL using Spring Data Jpa @Query. GQuery("select s from Student s where s.name = 21") List
getStudents (String name); Writing the Named Parameter @Query. aH Co TNE EIN aa SETS STRSTR) ListeStudent> FindByName(@Param(“name") String name); Write query method using JPA @NamedQuery and @NamedNativeQuery. entity @NamedQuery(name = "Student.findByName”, query = “select s from Student s where s.name = 21") public class Student { {fields and getter setter Create method in the repository using the same name as that of the query with one parameterExecuting DML queries OT op /JexecuteUpdate @Modi fying @query("update Contact set fname = 71 where email = 22") public int updateName (string fnm, string email); = DML queries even can be executed using for the custom methods in the repository. For executing it in a transaction, use @Modifying annotation above the method and @Transactior.al annotation above the repository. = The @Modifying annotation is used for INSERT, UPDATE, DELETE, and even DDL queries. When @Transactional annotation is declared at the class level, it applies as a default to all methods of the declaring class and its subclasses. It helps in commiting the updations to the database. Calling procedures from repository Obsyecr //preparecall @Procedure (name="getName", outputParameterName = "nm") public String getName(int cid); = In this case, repository method is annotated with @Procedure where “getName” is the name of the procedure and name of the output parameter is “nm” which is returned by the method as in the form of string.
You might also like
66 MERN Stack Interview Questions (ANSWERED) To Nail Your Next Tech Interview - FullStack - Cafe
PDF
No ratings yet
66 MERN Stack Interview Questions (ANSWERED) To Nail Your Next Tech Interview - FullStack - Cafe
21 pages
Intro DB JDBC JPA SpringData
PDF
No ratings yet
Intro DB JDBC JPA SpringData
136 pages
JavaScript Built-In Objects
PDF
100% (1)
JavaScript Built-In Objects
40 pages
Java Notes
PDF
No ratings yet
Java Notes
103 pages
CLG Java
PDF
No ratings yet
CLG Java
179 pages
Spring Framework Note by Biswajit Saha
PDF
No ratings yet
Spring Framework Note by Biswajit Saha
49 pages
Mongo DB
PDF
No ratings yet
Mongo DB
99 pages
Unit-1 Java Programming
PDF
100% (1)
Unit-1 Java Programming
54 pages
3.2 Es6 OOPs
PDF
No ratings yet
3.2 Es6 OOPs
29 pages
Advanced Java Programming Lab
PDF
No ratings yet
Advanced Java Programming Lab
100 pages
Sprint Boot Handy
PDF
No ratings yet
Sprint Boot Handy
24 pages
Master React in 20 Days
PDF
No ratings yet
Master React in 20 Days
33 pages
Spring Boot: Learncodewith Durgesh
PDF
No ratings yet
Spring Boot: Learncodewith Durgesh
27 pages
AdvJava 09 Combined
PDF
No ratings yet
AdvJava 09 Combined
124 pages
Java
PDF
No ratings yet
Java
152 pages
Namaste Javascript
PDF
No ratings yet
Namaste Javascript
59 pages
Spring Data JPA
PDF
No ratings yet
Spring Data JPA
12 pages
Typescript Tutorial
PDF
No ratings yet
Typescript Tutorial
17 pages
NodeJS Interview Docs
PDF
No ratings yet
NodeJS Interview Docs
37 pages
Javascript: Client-Side Scripting: of Web Development and of Web Development and
PDF
No ratings yet
Javascript: Client-Side Scripting: of Web Development and of Web Development and
94 pages
Introduction To Nodejs
PDF
No ratings yet
Introduction To Nodejs
7 pages
Chapter Six Java Web Technology
PDF
No ratings yet
Chapter Six Java Web Technology
44 pages
Introduction To Node - Js
PDF
No ratings yet
Introduction To Node - Js
21 pages
06 Spring Boot Spring MVC
PDF
No ratings yet
06 Spring Boot Spring MVC
22 pages
Servlet
PDF
No ratings yet
Servlet
52 pages
Spring MVC
PDF
No ratings yet
Spring MVC
44 pages
Data Structure in Javascript
PDF
No ratings yet
Data Structure in Javascript
138 pages
Rapid Fire Sunbeam
PDF
No ratings yet
Rapid Fire Sunbeam
10 pages
TERASOLUNAServer Framework For Java Development Guideline
PDF
No ratings yet
TERASOLUNAServer Framework For Java Development Guideline
2,321 pages
Spring 120 Boot Initilizr
PDF
No ratings yet
Spring 120 Boot Initilizr
23 pages
CICD Pipeline
PDF
No ratings yet
CICD Pipeline
10 pages
RESTFul Services
PDF
No ratings yet
RESTFul Services
25 pages
FullStack Presentation
PDF
No ratings yet
FullStack Presentation
19 pages
Lintroduction: Its Official Documentation Chrome'S Javascript Runtime
PDF
No ratings yet
Lintroduction: Its Official Documentation Chrome'S Javascript Runtime
35 pages
Object Oriented Javascript: © 2013, Cognizant Technology Solutions
PDF
No ratings yet
Object Oriented Javascript: © 2013, Cognizant Technology Solutions
42 pages
Java Fresher Resume
PDF
No ratings yet
Java Fresher Resume
2 pages
Frontend Interview
PDF
100% (1)
Frontend Interview
164 pages
Lara Java Course Content
PDF
No ratings yet
Lara Java Course Content
29 pages
L48 - MongoDB
PDF
No ratings yet
L48 - MongoDB
31 pages
Git Jenkins
PDF
No ratings yet
Git Jenkins
3 pages
CoreJava iNetSolv PDF
PDF
No ratings yet
CoreJava iNetSolv PDF
191 pages
Java Api
PDF
No ratings yet
Java Api
45 pages
Web Development: JAM-Geek Community
PDF
No ratings yet
Web Development: JAM-Geek Community
6 pages
Search Features: Arrow Functions
PDF
No ratings yet
Search Features: Arrow Functions
9 pages
Resume Java
PDF
No ratings yet
Resume Java
2 pages
React - Js Duration - 12 (Half Days)
PDF
No ratings yet
React - Js Duration - 12 (Half Days)
4 pages
Spring MVC Final Best
PDF
No ratings yet
Spring MVC Final Best
28 pages
What Is Spring Framework
PDF
No ratings yet
What Is Spring Framework
44 pages
Spring MVC Interview Questions and Answers: Minutes
PDF
No ratings yet
Spring MVC Interview Questions and Answers: Minutes
13 pages
Make API Call in NodeJS
PDF
No ratings yet
Make API Call in NodeJS
12 pages
Project Report On Rich Internet Application For Automatic College Timetable Generation (24th March 2008)
PDF
100% (1)
Project Report On Rich Internet Application For Automatic College Timetable Generation (24th March 2008)
112 pages
Top Nodejs ExpressJs IQ
PDF
No ratings yet
Top Nodejs ExpressJs IQ
58 pages
JS Data Structures
PDF
No ratings yet
JS Data Structures
9 pages
Unit 2
PDF
No ratings yet
Unit 2
33 pages
Introduction To RESTful Web Services
PDF
No ratings yet
Introduction To RESTful Web Services
21 pages
How To Write Clean Java Code PDF
PDF
No ratings yet
How To Write Clean Java Code PDF
1 page
Spring Boot
PDF
No ratings yet
Spring Boot
18 pages
Mca-303 (De2) - SM06
PDF
No ratings yet
Mca-303 (De2) - SM06
16 pages
SpringBoot-Training 1.0
PDF
No ratings yet
SpringBoot-Training 1.0
15 pages
Spring Boot
PDF
No ratings yet
Spring Boot
16 pages