Book description
Over 100 hands-on recipes to build Spring web applications easily and efficiently
Use the latest configuration style and web improvements in Spring 4 to write optimized code
Build full-featured web applications such as Spring MVC applications efficiently that will get you up and running with Spring web development
Learn dependency injection and aspect-oriented programming to create aspects that enable the modularization of concerns such as transaction management
In Detail
Spring is the most popular Java web framework. It makes it easy to efficiently build modular and testable web applications by using the Model-View-Controller paradigm and dependency injection.
Using this practical guide, you'll learn how to build a full-featured web application step-by-step, but with high efficiency using the latest improvements in Spring 4. Starting with the installation of Java, Maven, and Tomcat, you'll go on to create a basic MVC web application. You'll then add a database, forms, and user authentication, and learn how to handle mobile devices and integrate with Facebook and Twitter. Next, you will be introduced to unit testing, web services, and aspect-oriented programming.
Table of contents
-
Spring Cookbook
- Table of Contents
- Spring Cookbook
- Credits
- About the Author
- About the Reviewers
- www.PacktPub.com
- Preface
-
1. Creating a Spring Application
- Introduction
- Installing Java, Maven, Tomcat, and Eclipse on Mac OS
- Installing Java, Maven, Tomcat, and Eclipse on Ubuntu
- Installing Java, Maven, Tomcat, and Eclipse on Windows
- Creating a Spring web application
- Running a Spring web application
- Using Spring in a standard Java application
- 2. Defining Beans and Using Dependency Injection
-
3. Using Controllers and Views
- Introduction
- Associating a route to a controller method
- Using a JSP view
- Passing attributes from a controller to a JSP view
- Using dynamic route parameters in a controller method
- Using a common prefix for the routes of a controller
- Using a page template with Tiles
- Executing some code before and after controllers using interceptors
- Building multilingual pages
-
4. Querying a Database
- Introduction
- Connecting to a database
- Creating a DAO class
- Calling a DAO method from a controller class
- Saving an object
- Retrieving an object
- Retrieving a list of objects
- Retrieving a list of objects with their dependencies
- Updating an object
- Deleting an object
- Finding the number of results for an SQL query
- Saving a list of objects at once
- Reverting incomplete database modifications using transactions
- Using Hibernate for powerful object persistence and querying
-
5. Using Forms
- Introduction
- Displaying and processing a form
- Getting a submitted form value using a controller method argument
- Setting a form's default values using a model object
- Saving form data in an object automatically
- Using text, textarea, password, and hidden fields
- Using a select field
- Using a checkbox
- Using a list of checkboxes
- Using a list of radio buttons
- Validating a form using annotations
- Uploading a file
-
6. Managing Security
- Introduction
- Enabling Spring Security
- Authenticating users using the default login page
- Authenticating users using a custom login page
- Authenticating users using a database
- Adding a logout link
- Using public folders
- Authorizing only users with a specific role to view some pages
- Displaying page elements only to authenticated users in views
- Using HTTPS with Tomcat
-
7. Unit Testing
- Introduction
- Unit testing with JUnit 4
- Unit testing with TestNG 6
- Simulating dependencies with mocks using Mockito
- Unit testing with JUnit 4 using Spring's application context
- Unit testing with TestNG 6 using Spring's application context
- Unit testing with transactions
- Unit testing controller methods
-
8. Running Batch Jobs
- Introduction
- Installing and configuring Spring Batch
- Creating a job
- Executing a job from the command line
- Executing a job from a controller method
- Using job parameters
- Executing a system command
- Scheduling a job
- Creating a read/process/write step
- Reading an XML file
- Generating a CSV file
- Reading from a database
- Unit testing batch jobs
-
9. Handling Mobiles and Tablets
- Introduction
- Installing Spring Mobile
- Detecting mobiles and tablets
- Switching to the normal view on mobiles
- Using different JSP views for mobiles automatically
- Using a .mobi domain name on mobiles
- Using an m. subdomain on mobiles
- Using a different domain name on mobiles
- Using a subfolder path on mobiles
-
10. Connecting to Facebook and Twitter
- Introduction
- Creating a Facebook app
- Creating a test Facebook app and test users
- Connecting to Facebook
- Retrieving a Facebook user's profile
- Retrieving the list of friends of a Facebook user
- Posting a Facebook status update
- Posting a link to Facebook
- Posting a custom object to Facebook
- Creating a Twitter application
- Connecting to Twitter
- Retrieving a user's Twitter profile
- Retrieving the tweets of a Twitter user
- Posting a tweet to Twitter
- Sending a private message to another Twitter user
- 11. Using the Java RMI, HTTP Invoker, Hessian, and REST
-
12. Using Aspect-oriented Programming
- Introduction
- Creating a Spring AOP aspect class
- Measuring the execution time of methods using an around advice
- Logging method arguments using a before advice
- Logging methods' return values using an after-returning advice
- Logging exceptions using an after-throwing advice
- Using an after advice to clean up resources
- Making a class implement an interface at runtime using an introduction
- Setting the execution order of the aspects
- Index
Product information
- Title: Spring Cookbook
- Author(s):
- Release date: May 2015
- Publisher(s): Packt Publishing
- ISBN: 9781783985807
You might also like
book
Building Microservices, 2nd Edition
As organizations shift from monolithic applications to smaller, self-contained microservices, distributed systems have become more fine-grained. …
book
Clean Architecture: A Craftsman's Guide to Software Structure and Design
Building upon the success of best-sellers The Clean Coder and Clean Code, legendary software craftsman Robert …
book
JUnit in Action, Third Edition
JUnit in Action, Third Edition has been completely rewritten for this release. The book is full …
book
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn’t clean, it can bring a development organization …