Mastering Spring 5.0
Ranga Rao Karanam
- 496 pages
- English
- ePUB (adapté aux mobiles)
- Disponible sur iOS et Android
Mastering Spring 5.0
Ranga Rao Karanam
Ă propos de ce livre
Develop cloud native applications with microservices using Spring Boot, Spring Cloud, and Spring Cloud Data FlowAbout This Bookâą Explore the new features and components in Springâą Evolve towards micro services and cloud native applicationsâą Gain powerful insights into advanced concepts of Spring and Spring Boot to develop applications more effectivelyâą Understand the basics of Kotlin and use it to develop a quick service with Spring BootWho This Book Is ForThis book is for an experienced Java developer who knows the basics of Spring, and wants to learn how to use Spring Boot to build applications and deploy them to the cloud.What You Will Learnâą Explore the new features in Spring Framework 5.0âą Build microservices with Spring Bootâą Get to know the advanced features of Spring Boot in order to effectively develop and monitor applicationsâą Use Spring Cloud to deploy and manage applications on the Cloudâą Understand Spring Data and Spring Cloud Data Flowâą Understand the basics of reactive programmingâą Get to know the best practices when developing applications with the Spring Frameworkâą Create a new project using Kotlin and implement a couple of basic services with unit and integration testingIn DetailSpring 5.0 is due to arrive with a myriad of new and exciting features that will change the way we've used the framework so far. This book will show you this evolutionâfrom solving the problems of testable applications to building distributed applications on the cloud.The book begins with an insight into the new features in Spring 5.0 and shows you how to build an application using Spring MVC. You will realize how application architectures have evolved from monoliths to those built around microservices. You will then get a thorough understanding of how to build and extend microservices using Spring Boot. You will also understand how to build and deploy Cloud-Native microservices with Spring Cloud. The advanced features of Spring Boot will be illustrated through powerful examples. We will be introduced to a JVM language that's quickly gaining popularity - Kotlin. Also, we will discuss how to set up a Kotlin project in Eclipse.By the end of the book, you will be equipped with the knowledge and best practices required to develop microservices with the Spring Framework.Style and ApproachThis book follows an end-to-end tutorial approach with lots of examples and sample applications, covering the major building blocks of the Spring framework.
Foire aux questions
Informations
Building a Web Application with Spring MVC
- The Spring MVC architecture
- The roles played by DispatcherServlet, view resolvers, handler mappings and controllers
- Model attributes and session attributes
- Form binding and validation
- Integration with Bootstrap
- Basics of Spring Security
- Writing simple unit tests for controllers
Java web application architecture
- Model 1 architecture
- Model 2 or MVC architecture
- Model 2 with Front Controller
Model 1 architecture
- JSP pages directly handled the requests from the browser
- JSP pages made use of the model containing simple Java beans
- In some applications of this architecture style, JSPs even performed queries to the database
- JSPs also handled the flow logic: which page to show next
- Hardly any separation of concerns: JSPs were responsible for retrieving data, displaying data, deciding which pages to show next (flow), and sometimes, even business logic as well
- Complex JSPs: Because JSPs handled a lot of logic, they were huge and difficult to maintain
Model 2 architecture
- Model: Represents the data to be used to generate a View.
- View: Uses the Model to render the screen.
- Controller: Controls the flow. Gets the request from the browser, populates the Model and redirects to the View. Examples are Servlet1 and Servlet2 in the preceding figure.
Model 2 Front Controller architecture
- It decides which Controller executes the request
- It decides which View to render
- It provides provisions to add more common functionality
- Spring MVC uses an MVC pattern with Front Controller. The Front Controller is called DispatcherServlet. We will discuss DispatcherServlet a little later.
Basic flows
- Flow 1: Controller without a View; serving content on its own
- Flow 2: Controller with a View (a JSP)
- Flow 3: Controller with a View and using ModelMap
- Flow 4: Controller with a View and using ModelAndView
- Flow 5: Controller for a simple form
- Flow 6: Controller for a simple form with validation
Basic setup
- Add a dependency for Spring MVC.
- Add DispatcherServlet to web.xml.
- Create a Spring application context.
Adding dependency for Spring MVC
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
Adding DispatcherServlet to web.xml
<servlet>
<servlet-name>spring-mvc-dispatcher-servlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/user-web-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet...