34,79 €
If you are a Java developer with experience in developing applications with Spring, then this book is perfect for you. A good working knowledge of Spring programming conventions and applying dependency injections is recommended to make the most of this book.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 229
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: May 2015
Production reference: 1270515
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-732-0
www.packtpub.com
Author
Anjana Mankale
Reviewers
Nanda Nachimuthu
Chandan Sharma
Commissioning Editor
Julian Ursell
Acquisition Editor
Sonali Vernekar
Content Development Editor
Athira Laji
Technical Editor
Chinmay S. Puranik
Copy Editors
Sonia Michelle Cheema
Brandt D'Mello
Ulka Manjrekar
Project Coordinator
Harshal Ved
Proofreaders
Stephen Copestake
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Disha Haria
Abhinash Sahu
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
Anjana Mankale is a tech lead and has 8 years of experience in developing web applications. She has developed applications for healthcare, e-commerce portals, media portals, and content management systems using Spring and Struts2. She is extensively involved in application design and implementation. She has worked on Amazon Cloud and Spring Web Services and has recently been involved in deploying and designing cloud-based multitenant applications. Anjana has also authored a cookbook, Spring Security 3.x Cookbook, Packt Publishing.
Anjana is passionate about blogging (http://jtechspace.blogspot.in/), where she shares her write-ups and technical code that she has worked on.
I would like to thank my husband, Raghavendra S., for providing complete support and encouragement by intimating me about the timelines. This book is dedicated to my father, M. G. Prasad. Lastly, I would like to thank my parents and in-laws for their encouragement in completing this book.
Nanda Nachimuthu studied at IIT Kharaghpur and specializes in advanced Internet programming. He has 18 years of IT experience, which includes 10 years as an architect in various technologies, such as J2EE, SOA, ESB, Cloud, big data, and mobility.
He has designed, architected, and delivered many national projects and large-scale commercial projects. He is also involved in product design and development of various products in the insurance, finance, logistics, and life sciences domains.
Chandan Sharma is currently a software program analyst at Mroads, located in the US. It focuses on building the next generation workforce and leverages technology and awareness.. At Mroads, his primary responsibility is designing and implementing solutions that use Liferay, Spring Framework, and Hibernate for Portals, as well as for RESTful/SOAP Web services. Previously, he has worked as a senior consultant for Cignex Datamatics and TransIT mPower Labs. He also likes to coach people in the technology. Due to the experience he's gained throughout his career, he has developed hands-on experience in Liferay with Spring Framework, Hibernate and Liferay Integration with other applications, cloud technology, and so on. He also has his own technical blog at http://codingloading.com.
I would like to thank Packt Publishing for the opportunity given to me to review this book. I would like to thank Gaurav Vaish (author of Getting started with NoSQL, Packt Publishing) who inspired me to review this book. I would like to express my gratitude to my "rakhi" sister, Meenu Gupta, for her support and encouragement while reviewing this book. I am also grateful to my "cracked" group of friends (Monalisa Sahu, Manoj Patro, and Debasis Padhi) for encouraging me to do new things in my life. I would like to especially thank my best friend who helped me review this book.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Spring is an open source Java application development framework that is used to build and deploy systems and applications that run on a JVM. It makes efficiently built modular and testable web applications, by using a Model-View-Controller paradigm and dependency injection. It seamlessly integrates with numerous frameworks (such as Hibernate, MyBatis, Jersey, and so on), and reduces boilerplate code when using standard technologies, such as JDBC, JPA, and JMS.
The purpose of this book is to teach intermediate-level Spring developers to master Java application development with Spring, applying advanced concepts and using additional modules to extend the core framework. This is done to develop more advanced, strongly integrated applications.
Chapter 1, Spring Mongo Integration, demonstrates the integration of a Spring MVC with MongoDB along with installing MongoDB, to create database and collections.
Chapter 2, Messaging with Spring JMS, teaches you to install Apache ActiveMQ and different types of messaging. This chapter also demonstrates the creation of multiple queues and communicating with these queue using Spring templates with the help of screenshots.
Chapter 3, Mailing with Spring Mail, creates a mailing service and configures it using the Spring API, and demonstrates how to send mails with attachments using MIME messages.
Chapter 4, Jobs with Spring Batch, illustrates how Spring Batch can be used to read an XML file,and also how to create Spring-based batch applications to read a CSV file. This chapter also demonstrates how to write simple test cases using Spring Batch.
Chapter 5, Spring Integration with FTP, gives you an overviewof different types of adapters, such as inbound and outbound adapters, with an outbound gateway and its configurations. This chapter also looks into two important classes, FTPSessionFactory and FTPsSessionFactory, by using getter and setter.
Chapter 6, Spring Integration with HTTP, takes you through theuse of a multivalue map to populate a request and put the map in the HTTP header. Also, it will provide you with information about HTTP and Spring integration support, which can be used to access HTTP methods and requests.
Chapter 7, Spring with Hadoop, shows how Spring integrates with Apache Hadoop and provides Map and Reduce processes to search and count data. The chapter also discussed installing a Hadoop instance on Unix machines and configuring Hadoop jobs in a Spring framework.
Chapter 8, Spring with OSGI, develops a simple OSGI application, and also demonstrates how a Spring dynamic module supports OSGI development and reduces the creation of files, thereby making things easier with configuration.
Chapter 9, Bootstrap your Application with Spring Boot, starts with setting up a simple Spring boot project, along with the process of using a Spring Boot to bootstrap applications. This chapter also gives information about how a Spring Boot supports a cloud foundry server and helps to deploy applications on cloud.
Chapter 10, Spring Cache, implements our own caching algorithm and teaches you to make a generic algorithm. This chapter also discusses the classes and interface that support a caching mechanism in a Spring Framework.
Chapter 11, Spring with Thymeleaf Integration, integrates the Thymeleaf templating engine into a Spring MVC application, and also uses a Spring Boot to start Spring with a Thymeleaf application.
Chapter 12, Spring with Web Service Integration, integrates JAX_WS with Spring Web Service. It demonstrates how to create spring Web services and an endpoint class, accessing the web service by accessing the WSDL URL.
A computer with Mac OS, Ubuntu, or Windows is needed. To build Spring applications, you will need at least Java and Maven 3.
If you are a Java developer with experience in developing applications with Spring, then this book is perfect for you. A good working knowledge of Spring programming conventions and applying dependency injection is recommended to make the most of this book.
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: "We have used the @Controller annotation to indicate that the ProductController.java class is a controller class."
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
Any command-line input or output is written as follows:
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: "The next step is to create a rest controller to send a mail; to do so, click on Submit."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
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.
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.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.
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 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.
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.
MongoDB is a popular NoSQL database and is a document-based one too. It is written using the popular and powerful C++ language, which makes it a document-oriented database. Queries are also document-based, and it also provides indexing using JSON style to store and retrieve data. MongoDB works on the concept of collection and documentation.
Let's look at few terminology differences between MySQL and MongoDB:
MySQL
MongoDB
Table
Collection
Row
Document
Column
Field
Joins
Embedded documents linking
In MongoDB, a collection is a set or a group of documents. It is the same as RDBMS tables.
In this chapter, we shall start by setting up a MongoDB NoSQL database and will integrate a spring application with MongoDB to perform CRUD operations. The first example demonstrates updating single document values. The second example considers an order use case where it requires two document references to be stored in the collection. It demonstrates the flexibility in referencing different documents of MongoDB using objectId references.
We need to go for a NoSQL database only if the applications have heavy write operations. MongoDB also suits the cloud environment very well, where we can take copies of databases easily.
In the next section, we shall see how we can get started with MongoDB, beginning with installing it, using the Spring Framework, and integrating MongoDB. To get started, we shall show basic Create, Retrieve, Update, and Delete (CRUD) operations with various use cases.
In this section we shall install MongoDB and create a database:
The >show dbs command also works fine with MongoDB.
Execute the following command to create a new database, namely eshopdb.It's always easy to create a batch file to start MongoDB, and it's best to create a script file to start Mongo. This way, we won't have an error with the configuration. This would also save us a lot of time.
The next time you want to start MongoDB, just click on the batch file.
Let us look at the Order use case to implement a simple CRUD operation using Spring and MongoDB. We are performing CRUD operations on Product, Customer, and Order documents. The scenario is this: a customer selects a product and places an order.
Following is the Order use case. The actor is the application user and will have the following options:
Spring provides a simple way to map Mongo documents. The following table depicts the mapping of Bean with MongoDB collections:
Bean
Mongo Collections
Customer.java
db.customer.find()
Order.java
db.order.find()
Product.java
db.product.find()