Spring in Practice
eBook - ePub

Spring in Practice

Joshua White, Willie Wheeler

Share book
  1. 560 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Spring in Practice

Joshua White, Willie Wheeler

Book details
Book preview
Table of contents
Citations

About This Book

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

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Spring in Practice an online PDF/ePUB?
Yes, you can access Spring in Practice by Joshua White, Willie Wheeler in PDF and/or ePUB format, as well as other popular books in Informatik & Programmierung in Java. We have over one million books available in our catalogue for you to explore.

Information

Publisher
Manning
Year
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 of contents