Book Image

Learning Spring 5.0

By : Tejaswini Mandar Jog
Book Image

Learning Spring 5.0

By: Tejaswini Mandar Jog

Overview of this book

<p>Spring is the most widely used framework for Java programming and with its latest update to 5.0, the framework is undergoing massive changes. Built to work with both Java 8 and Java 9, Spring 5.0 promises to simplify the way developers write code, while still being able to create robust, enterprise applications.</p> <p>If you want to learn how to get around the Spring framework and use it to build your own amazing applications, then this book is for you.</p> <p>Beginning with an introduction to Spring and setting up the environment, the book will teach you in detail about the Bean life cycle and help you discover the power of wiring for dependency injection. Gradually, you will learn the core elements of Aspect-Oriented Programming and how to work with Spring MVC and then understand how to link to the database and persist data configuring ORM, using Hibernate.</p> <p>You will then learn how to secure and test your applications using the Spring-test and Spring-Security modules. At the end, you will enhance your development skills by getting to grips with the integration of RESTful APIs, building microservices, and doing reactive programming using Spring, as well as messaging with WebSocket and STOMP.</p>
Table of Contents (18 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
9
Explore the Power of RESTful Web Services

Preface

The world of Java development is flooded with many powerful frameworks equipped with many fascinating approaches. A core Java beginner or a developer is always in state of confusion when it comes to upgrading their skills. Which framework to choose to get the maximum benefit within the minimum time? The Spring framework is the first answer comes into my mind. No, not because I am writing a book about it. It's the power that helps developers in every stage of development to come up with a good quality product in minimum time. Spring Framework amazingly handles standalone applications and enterprise applications. The freedom in development is secret of its success. It doesn't force developers at any stage to be bonded with APIs but allows them to use them freely. The best thing is the developers can choose their own development style to follow. They don't need to worry about XML-based or annotation-based approach.

We have tried to make the book as simple as possible so that even a first-time reader will able to explore the framework on their own. Starting from very basic things such as bean and its configuration, each chapter smoothly takes you on a very interesting journey. We aim to move on gradually from an easy to complex configurations sequentially. The current working developers who don't want to go through one-by-one may open any page and start reading. You will always find it easy to follow.

The book is just not one more book that revises the concepts in Spring. We have tried to relate each concept from the previous version and the changes that have taken place in the new version. It's more of a philosophical relation. We have tried to cover everything in the new version from the ground up. We have taken all the efforts to make the book best suitable for learners at all stages.

Just leave the worries and go for it!

What this book covers

Chapter 1, Spring at Glance, explores the Spring Framework to grab the fundamental knowledge about what the framework is and its requirement. We will be discussing the journey of the framework and major changes which have taken place.

Chapter 2, Dependency Injection, talks about the basics of Spring. You will deep dive into the ocean of Spring fundamentals and it's working. You will explore the power of beans, dependency injection, bean scope, bean wiring, and many more things along with configurations.

Chapter 3, Accelerate with Spring DAO, deals with data handling to and from database. You will see and understand how Spring handles database using the concept of templates. You will also explore the ORM configuration and using cache in the application.

Chapter 4, Aspect-Oriented Programming, explains the cross-cutting technologies, the role played by them in an application, the traditional approach to handle them, and how Spring handles them. You will explore the concepts of aspects, pointcuts, advice, and weaving.

Chapter 5, Be Consistent - Transaction Management, explores database transaction management, its importance and types. You will be dealing with annotation-based transaction management done in a Spring application.

Chapter 6, Explore Spring MVC, talks a lot about Spring involved in developing web applications. You will be developing a web application step by step, incorporated with MVC architecture for form preprocessing, form handling, form validation, and many more such things.

Chapter 7, Be Assured, Take a Test Drive, is all about testing. You will be involved in understanding the importance of testing and the ways of testing an application. You will learn how to test Spring application using techniques such as Mock testing, Spring TestContext Framework, and Mockito testing. You will also see an introduction to Arquillian.

Chapter 8, Make It Safe - Security Managements, talks about securing management and ways to achieve it. You will see working of Spring security management with BASIC and FORM-based authentication. You will also get exposure to securing views and method-level security.

Chapter 9, Explore the Power of RESTful Web Services, is about web services, importance of web service, and its types. You will be developing an application using the concepts of RESTful webservices. You will be testing the developed application using Postman and RestTemplate for the testing purpose.

Chapter 10, Exchange Information - Use Messaging, deals with messaging using WebSocket. The chapter talks about STOMP along with an application development.

Chapter 11, Be Active - Reactive Programming, is about reactive programming as the most interesting new entry in Spring Framework. The chapter talks about basics of the reactive programming. You will also get orientation to the Spring support for reactive programming by developing an application. This chapter deals with messaging using WebSocket. The chapter talks about STOMP along with an application development.

What you need for this book

All you need is curiosity and patience along with the practical knowledge of Java. Any person who has basic practical knowledge of JDK and XML can start exploring Spring Framework. Basic knowledge about web programming, servlets, and JSP, handling databases (JDBC), object relational mapping, JUnit, the reactive programming will be an advantage to understand the code. The prior knowledge of Spring will obviously be an added advantage to understand the changes that have taken place in Spring 5. The exposure of the Eclipse IDE is required as we will be using it throughout the book.

Who this book is for

The book is designed in such a way that it will be helpful for both the beginners as well as the developers who are currently working with Spring-based application. Each chapter in the book starts with very basic things and slowly deep dives into the framework. The organization of the chapters will help even students of computer science who want to upgrade their skill with one of the most powerful frameworks in the market. The book covers the aspects involved in application development using Spring 5.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning. Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows:

"If the bean class implements the DisposableBean interface, its destroy() method will get called."

A block of code is set as follows:

 public Demo_Custom_Init() {
   // TODO Auto-generated constructor stub
   System.out.println("constructor gets called
     for initializing data membersin Custom init");
   message="welcome!!!"; name="no name";
 } 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public Demo_Custom_Init() {
  // TODO Auto-generated constructor stub
  System.out.println("constructor gets called
    for initializing data membersin Custom init");
message="welcome!!!"; name="no name";
}

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the Show form to add new Book link"

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learning-Spring-5.0. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.