Читать книгу Beginning Spring - Höller Jürgen - Страница 4
INTRODUCTION
WHAT THIS BOOK COVERS
ОглавлениеSpring provides a comprehensive configuration model, both with XML and Java annotations. Throughout the book we demonstrate both annotation-based configuration and XML-based configuration so that we give all the possible configuration scenarios.
The book first focuses on the core concepts and features of the Spring Framework. You take a look at the basic concepts, such as the non-invasive Plain Old Java Object (POJO) programming model approach, and then we define the Dependency Injection pattern (Inversion of Control). Spring also provides a Model View Controller implementation to build web applications; we cover the provided features in detail. The Java Database Connectivity and Java Persistence API features of the Spring Framework are also covered along with the transaction mechanism that it provides. We then focus on what Spring provides for doing test-driven development. Next we cover aspect-oriented programming for giving the reader insight on how Spring handles the implementation for cross-cutting concerns of a system. Spring Expression Languages, caching, and RESTful web services provide extensive features of the Spring Framework, and we cover them with real-world examples that will get you started on development within minutes. Then we dive into Spring Security, which became a de facto standard for applying security constraints on enterprise applications.
The final chapter wraps up the book with the latest features provided by version 4.0 of the framework. We describe the best of the breed because the book covers the major features of Spring by focusing on the latest version of the framework.
The following sections give you just a little bit of detail about what's covered in the 13 chapters of this book.
Dependency Injection and Configuration of Spring
This book covers the core concepts of the Spring Framework such as DI (which is also known as IoC) and its configuration model. The object-oriented programming principles depict having relationships between the objects that are instantiated. The main objective of the DI pattern is to separate the behaviors of those objects from the way that they depend on each other. That way the tenet of loose coupling is achieved with favoring usability and maintainability of the code. The idea of DI originated with Martin Fowler and has become very popular and widely adopted. It's also implemented within popular frameworks such as PicoContainer, Guice, and Spring.
The DI pattern resembles other patterns such as Factory or Strategy. We can say that with the Factory pattern the instantiation of objects is still within the responsibility of the Factory definition, which is your code, but with the DI it's externalized to another component/framework. On the other hand, with the Strategy pattern, the current implementation gets replaced with the help of multiple objects of a same interface, which contain that implementation inside. However, with the DI, the objects that contain those implementations are wired regardless of the implementation defined.
As of version 2.0 of the Spring Framework, the DI mechanism was being configured with the XML schemas along with the support of custom namespaces. As of version 2.5, Spring leveraged the use of Java 5 and the annotations to support auto discovery of components, annotation-driven autowiring of those components, and the life-cycle annotations to hook initialization and destruction callbacks. We cover all of these annotations introduced by the framework.
Spring 4.0
Chapter 13 covers the cutting-edge features of the latest version of Spring. Version 4.0 supports Java 8 with features like lambda expressions and method expressions. It also provides annotation-driven date formatting for the new DateTime API. Version 4.0 also complies with Java EE 7 specifications such as JPA 2.1, JMS 2.0, JTA 1.2, Bean Validation 1.1, and others. We demonstrate these features to give you insight about the best of breed of the most recent version.
Spring Annotations
Spring provides XML-based and annotation-based configuration mainly for dependency injection and also for the other features of the framework. We give the traditional XML configurations with the samples to show the complexity and the burden that they put on the developer. Throughout the book, we favor annotations wherever possible to ease your way and also to make the examples comprehensible in a practical way. We have tried to cover all of the annotations provided by the framework within the samples.
As of Spring 2.5, the JSR-250 Annotations API is also supported. It's the Java Specification Request that has the scope for annotation development, so it makes Spring more compliant with the EE edition of Java.
Spring Persistency Support with JDBC, JPA, and ORM
Spring provides an abstraction to the developers for JDBC database access. It eases development by reducing the boilerplate code for connection management, exception/transaction handling, and preparation and execution of the statements.
Spring doesn't provide a built-in object relational mapping (ORM) framework, but it supports well-known ORM frameworks that comply with the JPA specification, such as Hibernate, EclipseLink, TopLink, and others. The book covers all these features regarding JDBC, JPA, and ORM with step-by-step working samples.
Spring Expression Language (SpEL)
Spring Expression Language (SpEL) is a powerful expression language for navigating through object graphs at run time. All of the SpEL expressions can be defined in XML configurations or with annotations. The syntax used with SpEL resembles Unified EL, but it provides more enhanced features.
SpEL can be used to perform property or bean injections and method invocations. It also supports mathematical and relational operators along with regular expressions. SpEL can be easily used with other subprojects of Spring, such as Security or Caching. It's also technology-agnostic, so it can be used separately without depending on the Spring context. We cover each of these features with self-contained working samples.
Spring Transaction Management and AOP
Data integrity is one of the key points of every system that deals with the data. System behavior such as incorrect account balances, lost orders, or missing entries in a document will definitely be considered unacceptable by the system's users. Transaction management provides a way to achieve integrity on the data. Spring provides extensive transaction management to ensure this data integrity and consistency for enterprise applications. Chapter 6 uses sample code to show how Spring provides declarative and programmatic transaction mechanisms, the differences in local and global transactions, propagation rules on the transactions, and the commit/rollback architecture of the framework.
To implement the cross-cutting concerns, Spring AOP provides easy definition of the elements of AOP with XML configuration, but it also supports the AspectJ framework annotations to easily configure the application.
Spring MVC and Developing RESTful Web Services
With the Model View Controller (MVC) pattern, the enterprise application can be clearly defined with three layers. Model is the part of the application that handles the logic for the application data. View is the part that handles the display of the data, and Controller is the part that handles the user interaction. Spring provides an MVC subproject to handle the HTTP requests by reducing the boilerplate code needed for accessing request parameters, validations, and conversations and model updates. It also provides a convenient way to define RESTful web services to be used with cutting-edge user-interface frameworks to provide more responsive web applications.
Spring Security
Spring Security is the subproject that provides first-class authentication and authorization support for Java-based enterprise applications. The project first started as codename Acegi and then merged into the Spring portfolio. The project conforms to the Servlet API, so it's easy to integrate it with a Java EE–based web application. It also provides optional integration with other Spring frameworks, such as MVC, so it gives consistent usage on its features. In Chapter 12 we provide some neat examples for these feature foundations.
Spring Cache
By starting with version 3.1, Spring Framework provides a transparent caching abstraction for enterprise applications by employing various caching frameworks, such as Ehcache and Hazelcast, in the backend.
The main objective of caching is to reduce the execution of targeted methods by caching the results of method returns with their executed parameters.
NOTE The Spring Framework is a comprehensive toolset that cannot be covered in a beginner-level book with all of its subprojects and the whole set of their features. This book might not be suitable for readers who seek a showdown of Spring subprojects with an end-to-end explanation.
This book also focuses on version 4.0.5.RELEASE of the framework, which is the most recent version at the time of writing. Thus the older versions of the framework are not covered with their features in this book.