Spring in Practice
eBook - ePub

Spring in Practice

Joshua White, Willie Wheeler

Partager le livre
  1. 560 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Spring in Practice

Joshua White, Willie Wheeler

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Summary Spring in Practice shows you how to tackle the challenges you face when you build Spring-based applications. The book empowers software developers to solve concrete business problems by mapping application-level issues to Spring-centric solutions. It diverges from other cookbooks because it presents the background you need to understand the domain in which a solution applies before it offers the specific steps to solve the problem. About this Book Spring in Practice covers 66 Spring development techniques and the practical issues you will encounter when using them. The book starts with three carefully crafted introductory chapters to get you up to speed on the fundamentals. And then, the core of the book takes you step-by-step through the important, practical techniques you will use no matter what type of application you're building. You'll hone your Spring skills with examples on user accounts, security, NoSQL data stores, and application integration. Along the way, you'll explore Spring-based approaches to domain-specific challenges like CRM, configuration management, and site reliability. What's Inside

  • Covers Spring 3
  • Successful outcomes with integration testing
  • Dozens of web app techniques using Spring MVC
  • Practical examples and real-world context
  • How to work effectively with data


Each technique highlights something new or interesting about Spring and focuses on that concept in detail. This book assumes you have a good foundation in Java and Java EE. Prior exposure to Spring Framework is helpful but not required.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Authors Willie Wheeler is a Principal Applications Engineer with 16 years of experience in Java/Java EE and Spring Framework. Joshua White is a Solutions Architect in the financial and health services industries. He has worked with Spring Framework since its inception in 2002. Table of Contents

  • Introducing Spring: the dependency injection container
  • Data persistence, ORM, and transactions
  • Building web applications with Spring Web MVC
  • Basic web forms
  • Enhancing Spring MVC applications with Web Flow
  • Authenticating users
  • Authorizing user requests
  • Communicating with users and customers
  • Creating a rich-text comment engine
  • Integration testing
  • Building a configuration management database
  • Building an article-delivery engine
  • Enterprise integration
  • Creating a Spring-based "site-up" framework

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Spring in Practice est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Spring in Practice par Joshua White, Willie Wheeler en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming in Java. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Éditeur
Manning
Année
2013
ISBN
9781638353782

Chapter 1. Introducing Spring: the dependency injection container

This chapter covers
  • Major functional areas of the Spring Framework
  • Flexible configuration using dependency injection
  • Wiring beans using XML
  • Autowiring and component scanning using annotations
In this chapter, we’ll provide a brief overview of the Spring Framework, beginning with a discussion of what Spring is and giving an overview of its major pieces. Then we’ll delve into the underlying principles behind the Spring Framework, and talk about inversion of control and how it relates to dependency injection. Finally, we’ll dive into a small example that shows how to use the Spring Core Container hands-on. Let’s get started.

1.1. What is Spring, and why use it?

The Spring Framework is an open source application framework created to simplify the development of enterprise Java software. The framework achieves this goal by providing developers with a component model and a set of simplified and consistent APIs that effectively insulate developers from the complexity and error-prone boilerplate code required to create complex applications.
Over the last nine years, the breadth and depth of the framework has increased significantly, yet it has remained simple to learn and easy to use. The framework has evolved into roughly 20 modules that can be grouped into 6 basic functional areas. As shown in figure 1.1, these functional areas are Data Access/Integration, Web, Aspect-Oriented Programming (AOP), Instrumentation, the Core Container, and Test.
Figure 1.1. A high-level block diagram illustrating Spring’s six basic functional areas
This modularity gives developers the freedom to choose which parts of the framework to use in their applications without the need to include the entire framework. Let’s begin our tour by looking at each of these functional areas.

1.1.1. The major pieces of the framework

In the paragraphs that follow, we’ll give you a brief introduction to each of Spring’s six basic functional areas. We’ll take a deeper dive into each of these topics as we work through individual recipes later in the book.
The Core Spring Container
We’ll further dissect what dependency injection (DI) is in section 1.2. For now, it’s enough to know that the DI container is at the core of the Spring Framework and provides the fundamental capabilities on which all the other modules are built. The container provides the facility for decoupling the creation, configuration, and management of beans (discussed later) from your application code.
Aspect-oriented programming (AOP)
The Spring Framework also supports aspect-oriented programming with both a simpler approach called Spring AOP and the more powerful AspectJ approach. AOP, which is covered in more detail later, aims to encapsulate cross-cutting concerns (security, logging, transaction management, and so on) into aspects to retain modularity and reusability. These concerns often can’t be cleanly decomposed from the rest of the system and can result in code duplication, significant dependencies between systems, or both. Like the DI container, AOP support is both independently useful to developers and used to implement different parts of framework functionality. For example, Spring implements its support for declarative transaction management through AOP because transactions are a cross-cutting concern.
Data Access/Integration
The Data Access/Integration module provides support for the Java Database Connectivity API (JDBC), object-relational mapping (ORM), Object/XML mapping (OXM), Java Message Service (JMS), and transactional support.
The JDBC module provides an abstraction layer that relieves developers from having to write tedious and error-prone boilerplate code by automatically managing database connections and connection pools, and by mapping vendor-specific errors into a uniform exception hierarchy. It also makes it easy to map java.sql.ResultSets to lists of domain objects and execute stored procedures.
If you prefer to use ORM instead of straight JDBC for database access code, you’re in luck. The ORM module supports the best and most popular ORMs available, including Hibernate, iBATIS, Java Data Objects (JDO), and the Java Persistence API (JPA).
A quick note about iBATIS
Apache iBATIS was retired in 2010 and has been superseded by MyBatis (mybatis.org). Although iBATIS 2 has been supported since Spring 2, due to release timing issues, Spring 3 doesn’t yet include official support for it. See the MyBatis-Spring module at www.mybatis.org/spring.
The OXM module provides an abstraction layer that offers simplified and consistent support for popular Object/XML mapping tools such as Castor, the Java Architecture for XML Binding (JAXB), JiBX, XMLBeans, and XStream.
The JMS module provides simplified APIs for producing and consuming messages. Finally, the Transaction module provides support for both programmatic and declarative transaction management.
Web
Spring’s Web module provides common web infrastructure code for integrating Spring into web applications, multipart file upload, and web-based remoting capabilities. In addition to providing its own servlet- or portlet-based Model-View-Controller (MVC) framework, this module integrates with popular web-development frameworks and technologies like Struts, JavaServer Faces (JSF), Velocity, FreeMarker, and JavaServer Pages (JSP).
Test
Last but not least in the framework stack is Spring’s testing support. This module provides support for using both the JUnit and TestNG frameworks.
Now that we’ve provided a high-level overview of the Spring Framework, let’s discuss the benefits of using the framework.

1.1.2. Why use it?

You may have worked with or even developed other frameworks or APIs that handle one or more of the Spring Framework’s concerns. Why would you stop to learn something that requires a fairly substantial time investment? In addition to providing you with a component model and a simplified and consistent set of APIs that effectively insulate developers from complexity and error-prone boilerplate code, here are other reasons:
  • Quality— From the overall design of the modules, packages, class structures, and APIs to the implementation and test coverage of the source code, the Spring Framework is a great example of high-quality open source software.
  • Modularity— As we mentioned earlier, the framework has evolved into roughly 20 modules, giving developers the freedom to choose which parts of the framework to use in their applications without the need to include the entire framework.
  • Promotes best practices— Spring’s plain old Java object (POJO)-based programming model promotes decoupled component models, unit testing, and other best practices.
  • Modest learning curve— Due to the consistency and simplicity of the APIs, Spring isn’t hard to learn. As we make our way through the framework, you’ll see that common patterns emerge. Plus, hundreds of resources online and in print are at your disposal, including message boards where the core developers often participate.
  • Popularity— As evidenced by myriad publications, websites, and job postings, the Spring Framework is almost ubiquitous.
For an excellent print reference that will certainly be of aid during your journey with this book, check out Craig Walls’ Spring in Action, 3rd Edition (Manning Publications, 2011).
Spring offers a lot, and it takes time to understand and appreciate the landscape. But rest assured that the effort is well worth it. By learning Spring and using it to solve problems, you’ll see how to bring together disparate technologies and incorporate them into cohesive applications. You’ll keep hardcoded configuration parameters out of your classes and centralized in standard locat...

Table des matiĂšres