Beginning Spring. Höller Jürgen

Читать онлайн.
Название Beginning Spring
Автор произведения Höller Jürgen
Жанр Зарубежная образовательная литература
Серия
Издательство Зарубежная образовательная литература
Год выпуска 0
isbn 9781118893111



Скачать книгу

and authorization, logging, and caching. The DI and AOP concepts are covered in detail in Chapters 2 and 8, respectively.

      With the help of these major features, Spring provides easily testable, reusable code with no vendor lock-in because it can be ported easily between application servers such as WebLogic, JBoss, and Tomcat. With its layered architecture, it addresses different parts of complex enterprise application development.

      We can definitely say that the Spring Framework has become the de facto standard for developing Java enterprise applications. In this book you will find all of the major features brought to the enterprise world by the framework.

      WHO THIS BOOK IS FOR

      As the book's title states, this book covers the Spring Framework on a beginner level, and it touches on intermediate concepts wherever needed. It explains what the framework offers and also illustrates the content by showing how these features actually work with comprehensive samples. The material presented within the book is suitable for Enterprise application developers who haven't tried the Spring Framework yet or who don't know the details of its core or the subprojects. The book will also be helpful to middle-level management, who will be enlightened about the ingredients of enterprise application development and will get to taste the different flavors of the Spring Framework.

      We assume that readers have some knowledge of Java language principles and the ability to develop Java code with integrated development environments (IDEs) such as Eclipse, NetBeans, or others.

      This book might not be suitable for people who are not familiar with the Java language and basic object-oriented programming concepts. We also believe that the book might be of no interest for readers who are not keen on the enterprise application development world with Java.

      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