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)
188 views
SpringBOOT PDF
Uploaded by
AKSHAY ANDURE
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SpringBOOT.pdf For Later
Download
Save
Save SpringBOOT.pdf For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
188 views
SpringBOOT PDF
Uploaded by
AKSHAY ANDURE
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SpringBOOT.pdf For Later
Carousel Previous
Carousel Next
Save
Save SpringBOOT.pdf For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
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
JavaScript Interview Questions
PDF
No ratings yet
JavaScript Interview Questions
13 pages
Lara Java Course Content
PDF
No ratings yet
Lara Java Course Content
29 pages
Spring MVC Interview Questions and Answers: Minutes
PDF
No ratings yet
Spring MVC Interview Questions and Answers: Minutes
13 pages
Chapter Six Java Web Technology
PDF
No ratings yet
Chapter Six Java Web Technology
44 pages
Rapid Fire Sunbeam
PDF
No ratings yet
Rapid Fire Sunbeam
10 pages
ASP.Net
PDF
No ratings yet
ASP.Net
126 pages
Spring Framework Note by Biswajit Saha
PDF
No ratings yet
Spring Framework Note by Biswajit Saha
49 pages
Java Fresher Resume
PDF
No ratings yet
Java Fresher Resume
2 pages
MERN Stack Interview Questions (2024)
PDF
100% (1)
MERN Stack Interview Questions (2024)
24 pages
Github Com Sudheer...
PDF
No ratings yet
Github Com Sudheer...
181 pages
Java Collections Framework PDF
PDF
No ratings yet
Java Collections Framework PDF
62 pages
NodeJs Questions and Answers
PDF
No ratings yet
NodeJs Questions and Answers
18 pages
How To Write Clean Java Code PDF
PDF
No ratings yet
How To Write Clean Java Code PDF
1 page
Spring 120 Boot Initilizr
PDF
No ratings yet
Spring 120 Boot Initilizr
23 pages
3.2 Es6 OOPs
PDF
No ratings yet
3.2 Es6 OOPs
29 pages
Top Nodejs ExpressJs IQ
PDF
No ratings yet
Top Nodejs ExpressJs IQ
58 pages
AdvJava 09 Combined
PDF
No ratings yet
AdvJava 09 Combined
124 pages
ASPNET
PDF
No ratings yet
ASPNET
6 pages
Unit-7: Java Web Frameworks: Spring MVC
PDF
No ratings yet
Unit-7: Java Web Frameworks: Spring MVC
26 pages
MVC 5 Intro PDF
PDF
No ratings yet
MVC 5 Intro PDF
35 pages
Core Java Notes
PDF
No ratings yet
Core Java Notes
19 pages
Class Notes
PDF
No ratings yet
Class Notes
42 pages
Web Services
PDF
No ratings yet
Web Services
10 pages
FullStack Presentation
PDF
No ratings yet
FullStack Presentation
19 pages
Spring MVC Final Best
PDF
No ratings yet
Spring MVC Final Best
28 pages
Full Stack Curriculum.
PDF
No ratings yet
Full Stack Curriculum.
8 pages
JavaScript Built-In Objects
PDF
No ratings yet
JavaScript Built-In Objects
40 pages
Css Interview Questions
PDF
No ratings yet
Css Interview Questions
7 pages
JDBC 4pm NTAJ414 All Paintbrush
PDF
No ratings yet
JDBC 4pm NTAJ414 All Paintbrush
66 pages
Object Oriented Javascript: © 2013, Cognizant Technology Solutions
PDF
No ratings yet
Object Oriented Javascript: © 2013, Cognizant Technology Solutions
42 pages
Pluralsight - Angular Reactive Forms
PDF
No ratings yet
Pluralsight - Angular Reactive Forms
190 pages
Dart Language Specification
PDF
No ratings yet
Dart Language Specification
122 pages
CoreJava iNetSolv PDF
PDF
No ratings yet
CoreJava iNetSolv PDF
191 pages
Resume Java
PDF
No ratings yet
Resume Java
2 pages
An Introduction To Struts 1
PDF
No ratings yet
An Introduction To Struts 1
39 pages
Spring Interview Questions
PDF
No ratings yet
Spring Interview Questions
84 pages
Namaste Javascript
PDF
No ratings yet
Namaste Javascript
59 pages
Spring MVC
PDF
No ratings yet
Spring MVC
46 pages
JSP Interview Questions and Answers
PDF
No ratings yet
JSP Interview Questions and Answers
7 pages
J2EE (Advanced) JAVA
PDF
No ratings yet
J2EE (Advanced) JAVA
141 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
TERASOLUNAServer Framework For Java Development Guideline
PDF
No ratings yet
TERASOLUNAServer Framework For Java Development Guideline
2,321 pages
Java Notes
PDF
No ratings yet
Java Notes
103 pages
[Ebooks PDF] download Node js MongoDB and Angular Web Development The definitive guide to using the MEAN stack to build web applications Developer s Library 2nd Edition Brad Dayley & Brendan Dayley & Caleb Dayley full chapters
PDF
100% (4)
[Ebooks PDF] download Node js MongoDB and Angular Web Development The definitive guide to using the MEAN stack to build web applications Developer s Library 2nd Edition Brad Dayley & Brendan Dayley & Caleb Dayley full chapters
62 pages
What Is Struts?
PDF
No ratings yet
What Is Struts?
55 pages
Angular Cheat Sheet: Click Here
PDF
No ratings yet
Angular Cheat Sheet: Click Here
17 pages
Web Services: 1. SSL Certificates
PDF
No ratings yet
Web Services: 1. SSL Certificates
9 pages
Chapter 5 Bootstrap
PDF
No ratings yet
Chapter 5 Bootstrap
31 pages
R Bootstrap PDF
PDF
No ratings yet
R Bootstrap PDF
5 pages
Angularjs Is An Web Based Applicatio
PDF
No ratings yet
Angularjs Is An Web Based Applicatio
1 page
SpringBoot-Training 1.0
PDF
No ratings yet
SpringBoot-Training 1.0
15 pages
Unit 2
PDF
No ratings yet
Unit 2
33 pages
Mca-303 (De2) - SM06
PDF
No ratings yet
Mca-303 (De2) - SM06
16 pages
Lecture 1 - Spring Boot Introduction
PDF
No ratings yet
Lecture 1 - Spring Boot Introduction
40 pages
Spring Boot Using Maven
PDF
No ratings yet
Spring Boot Using Maven
10 pages
Unit 5
PDF
No ratings yet
Unit 5
10 pages
I28 Springboot Microservices
PDF
No ratings yet
I28 Springboot Microservices
129 pages
Introducing To Spring Boot
PDF
No ratings yet
Introducing To Spring Boot
13 pages
Spring Boot Interview Questions: 10 Step Reference Courses
PDF
No ratings yet
Spring Boot Interview Questions: 10 Step Reference Courses
18 pages
Spring Boot Interview Questions: 10 Step Reference Courses
PDF
No ratings yet
Spring Boot Interview Questions: 10 Step Reference Courses
18 pages