O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Spring Essentials

Book Description

Build mission-critical enterprise applications using Spring Framework and Aspect Oriented Programming

About This Book

  • Step into more advanced features of aspect-oriented programming and API components to build enterprise grade systems

  • Build lightning-fast web applications and REST APIs using Spring MVC and its asynchronous processing capabilities with the view technologies of your choice

  • Explore simplified but powerful data access techniques including JPA (Java Persistence Architecture) repositories and NoSQL data access

  • Who This Book Is For

    Explore simplified but powerful data access techniques including JPA (Java Persistence Architecture) repositories and NoSQL data access

    What You Will Learn

  • Set up and build standalone and web-based projects using Spring Framework with Maven or Gradle

  • Get familiar with JSP Form processing using Spring and Form Tag Library

  • Develop RESTful API applications for XML and JSON data transfers with non-blocking asynchronous capabilities

  • Explore Spring’s comprehensive transaction support for declarative Transaction Management and its integration with Spring’s data access abstractions

  • Investigate Spring Data access mechanisms with Spring Data Repositories, a simple and consistent data-access abstraction

  • Construct real-time applications using WebSocket with a SockJS fallback option

  • Understand how to secure your Spring Web and standalone applications using Spring Security declaratively and consistently

  • Get to grips with the end-to-end development of an API-based modern SPA using EmberJS at the front end and SpringMVC at the back end

  • In Detail

    Spring is an open source Java application development framework to build and deploy systems and applications that run on the JVM. It is the industry standard and the most popular framework among Java developers with over two-thirds of developers using it.

    Spring Essentials makes learning Spring so much quicker and easier with the help of illustrations and practical examples. Starting from the core concepts of features such as inversion of Control Container and BeanFactory, we move on to a detailed look at aspect-oriented programming. We cover the breadth and depth of Spring MVC, the WebSocket technology, Spring Data, and Spring Security with various authentication and authorization mechanisms.

    Packed with real-world examples, you’ll get an insight into utilizing the power of Spring Expression Language in your applications for higher maintainability. You’ll also develop full-duplex real-time communication channels using WebSocket and integrate Spring with web technologies such as JSF, Struts 2, and Tapestry. At the tail end, you will build a modern SPA using EmberJS at the front end and a Spring MVC-based API at the back end.By the end of the book, you will be able to develop your own dull-fledged applications with Spring.

    Style and approach

    This book is a practical guide based on logical modules of the whole Spring Framework family, with a start-small approach, increasing in complexity as it progresses. Every chapter is an amalgamation of theory and practical examples, with further discussion on additional features and approaches.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Spring Essentials
      1. Table of Contents
      2. Spring Essentials
      3. Credits
      4. About the Authors
      5. About the Reviewer
      6. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why subscribe?
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Getting Started with Spring Core
        1. The Spring landscape
          1. The Spring Framework modules
          2. Spring Tool Suite (STS)
          3. Spring subprojects
        2. Design concepts behind Spring Framework
        3. Setting up the development environment
        4. Your first Spring application
          1. Inversion of Control explained
        5. Dependency Injection
          1. The Spring IoC container
          2. Configuration metadata
            1. XML-based configuration metadata
            2. Annotation-based configuration metadata
            3. XML-based versus annotation-based configuration
            4. Component stereotype annotations
            5. Java-based configuration metadata
            6. JSR 330 standard annotations
        6. Beans in detail
          1. Bean definition
          2. Instantiating beans
            1. With constructors
            2. With a static factory-method
            3. With an instance factory-method
          3. Injecting bean dependencies
            1. Constructor-based Dependency Injection
            2. Setter-based Dependency Injection
          4. Constructor-based or setter-based DI – which is better?
          5. Cleaner bean definitions with namespace shortcuts
          6. Wiring a List as a dependency
          7. Wiring a Map as a dependency
          8. Autowiring dependencies
          9. Bean scoping
          10. Dependency Injection with scoped beans
          11. Creating a custom scope
        7. Hooking to bean life cycles
          1. Implementing InitializingBean and DisposableBean
          2. Annotating @PostConstruct and @PreDestroy on @Components
          3. The init-method and destroy-method attributes of <bean/>
        8. Container-level default-init-method and default-destroy-method
        9. Working with bean definition profiles
        10. Injecting properties into the Spring environment
        11. Externalizing properties with PropertyPlaceholderConfigurer
        12. Handling resources
        13. Spring Expression Language
          1. SpEL features
          2. SpEL annotation support
          3. The SpEL API
        14. Aspect Oriented Programming
          1. Static and dynamic AOP
          2. AOP concepts and terminology
          3. Spring AOP – definition and configuration styles
          4. XML schema-based AOP
          5. @AspectJ annotation-based AOP
          6. Declaring an @Aspect annotation
            1. Pointcuts
              1. Pointcut designators
              2. Pointcut examples
            2. Advices
              1. The @Around Advice
              2. Accessing Advice parameters
        15. Testing with Spring
          1. Mock objects
          2. Unit and integration testing utilities
        16. Summary
      9. 2. Building the Web Layer with Spring Web MVC
        1. Features of Spring MVC
        2. The Model-View-Controller pattern
        3. Your first Spring MVC application
        4. Setting up a Spring MVC application
          1. The project structure of a Spring MVC application
          2. The web.xml file – Springifying the web app
          3. ApplicationContext files in a Spring MVC application
          4. HomeController – @Controller for the home screen
          5. The home.jsp file – the landing screen
          6. Handling incoming requests
        5. The architecture and components of Spring MVC
        6. DispatcherServlet explained
          1. WebApplicationContext – ApplicationContext for the Web
          2. Beans supporting DispatcherServlet and their roles
        7. Controllers in detail
          1. Mapping request URLs with @RequestMapping
          2. URI template patterns with the @PathVariable annotation
          3. Binding parameters with the @RequestParam annotation
          4. Request handler method arguments
          5. Request handler method return types
          6. Setting Model attributes
          7. Building RESTful services for JSON and XML media
          8. Building a RESTful service with RestController
        8. Asynchronous request processing in Spring MVC
        9. Working with views
          1. Resolving views
          2. Resolving JSP views
          3. Binding Model attributes in JSP pages using JSTL
        10. Spring and Spring form tag libraries
        11. Composing a form in JSP
        12. Validating forms
        13. Handling file uploads
        14. Resolving Thymeleaf views
        15. More view technologies
        16. Summary
      10. 3. Accessing Data with Spring
        1. Configuring DataSource
        2. Using embedded databases
        3. Handling exceptions in the Spring Data layer
        4. DAO support and @Repository annotation
        5. Spring JDBC abstraction
          1. JdbcTemplate
            1. NamedParameterJdbcTemplate
          2. SimpleJdbc classes
          3. JDBC operations with Sql* classes
        6. Spring Data
          1. Spring Data Commons
          2. Spring Data repository specification
            1. Spring Data JPA
            2. Enabling Spring Data JPA
            3. JpaRepository
          3. Spring Data MongoDB
            1. Enabling Spring Data MongoDB
            2. MongoRepository
          4. Domain objects and entities
            1. Query resolution methods
            2. Using the @Query annotation
            3. Spring Data web support extensions
            4. Auditing with Spring Data
        7. Spring Transaction support
        8. Relevance of Spring Transaction
          1. Spring Transaction fundamentals
          2. Declarative transaction management
            1. Transactional modes – proxy and AspectJ
            2. Defining transactional behavior
            3. Setting rollback rules
          3. Using the @Transactional annotation
            1. Enabling transaction management for @Transactional
          4. Programmatic transaction management
        9. Summary
      11. 4. Understanding WebSocket
        1. Creating a simple WebSocket application
        2. STOMP over WebSocket and the fallback option in Spring 4
        3. Broadcasting a message to a single user in a WebSocket application
        4. Summary
      12. 5. Securing Your Applications
        1. Authentication
        2. Authorization
          1. The OAuth2 Authorization Framework
        3. Summary
      13. 6. Building a Single-Page Spring Application
        1. The motivations behind SPAs
        2. SPAs explained
          1. The architectural benefits of SPAs
          2. SPA frameworks
        3. Introducing Ember.js
        4. The anatomy of an Ember application
          1. Routers
          2. Routes or route handlers
          3. Templates
          4. Components
          5. Models
          6. Controllers
          7. Input helpers
          8. Custom helpers
          9. Initializers
          10. Services
        5. Working with Ember CLI
          1. Setting up Ember CLI
          2. Getting started with Ember CLI commands
          3. The Ember project structure
          4. Working with the POD structure
        6. Understanding the Ember object model
          1. Declaring types (classes) and instances
          2. Accessing and mutating properties
          3. Computed properties
          4. Property observers
        7. Working with collections
        8. Building UI templates using Handlebars
          1. Handlebars helpers
          2. Data binding with input helpers
          3. Using control flow helpers in Handlebars
          4. Using event helpers
        9. Handling routes
        10. Handling UI behavior using components
          1. Building a ToggleButton component step by step
        11. Persisting data with Ember Data
          1. Ember Data architecture
          2. Defining models
          3. Defining model relationships
        12. Building a Taskify application
        13. Building the API server app
          1. Setting up and configuring the project
          2. Defining the model definitions – User and Task
          3. Building API endpoints for the Taskify app
            1. UserController.java
            2. TaskController.java
        14. Building the Taskify Ember app
          1. Setting up Taskify as an Ember CLI project
          2. Setting up Ember Data
          3. Configuring application routes
          4. Building the home screen
          5. Building the user screen
          6. Building a custom helper
          7. Adding action handlers
          8. Building a custom component – modal window
            1. Building userEditModal using {{modal-window}}
          9. Building the task screen
        15. Summary
      14. 7. Integrating with Other Web Frameworks
        1. Spring's JSF integration
        2. Spring's Struts integration
        3. Summary
      15. Index