Building Web Apps with Spring 5 and Angular

Book description

A complete guide to build robust and scalable web applications with Spring and Angular.

About This Book

  • This hands on guide will teach you how to build an end-to-end modern web application using Spring and Angular.
  • It is easy to read and will benefit Java developers who have been used to develop the back-end part of web application while front-end (UI) has been left for UI developers.
  • Learn the core aspects involved in developing the backend and the UI, right from designing to integrating and deploying.

Who This Book Is For

This book is targeted towards Java Web Developers with a basic knowledge of Spring who want to build complete web applications in a fast and effective way. They will want to gain a stronghold on both frontend and backend development to advance in their careers.

What You Will Learn

  • Set up development environment for Spring Web App and Angular app.
  • Process web request and response and build REST API endpoints.
  • Create data access components using Spring Web MVC framework and Hibernate
  • Use Junit 5 to test your application
  • Learn the fundamental concepts around building Angular
  • Configure and use Routes and Components.
  • Protect Angular app content from common web vulnerabilities and attacks.
  • Integrate Angular apps with Spring Boot Web API endpoints
  • Deploy the web application based on CI and CD using Jenkins and Docker containers

In Detail

Spring is the most popular application development framework being adopted by millions of developers around the world to create high performing, easily testable, reusable code. Its lightweight nature and extensibility helps you write robust and highly-scalable server-side web applications. Coupled with the power and efficiency of Angular, creating web applications has never been easier.

If you want build end-to-end modern web application using Spring and Angular, then this book is for you.

The book directly heads to show you how to create the backend with Spring, showing you how to configure the Spring MVC and handle Web requests. It will take you through the key aspects such as building REST API endpoints, using Hibernate, working with Junit 5 etc. Once you have secured and tested the backend, we will go ahead and start working on the front end with Angular. You will learn about fundamentals of Angular and Typescript and create an SPA using components, routing etc. Finally, you will see how to integrate both the applications with REST protocol and deploy the application using tools such as Jenkins and Docker.

Style and approach

This is a straightforward guide that shows how to build a complete web application in Angular and Spring.

Table of contents

  1. 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
  2. Introduction to Spring Web Framework
    1. Introduction to the Spring IOC container
      1. What is IOC?
      2. What is a Spring IOC container?
    2. Introduction to Spring Web MVC
      1. Key building blocks of a Spring Web MVC application
      2. Introduction to the Dispatcher servlet
    3. Building Hello World web application with Spring Boot
      1. The Spring STS Setup in Eclipse IDE
      2. Introduction to Spring Boot
      3. Building  Hello World web app using Spring Boot
    4. Implementing Controllers
    5. Handling request parameters
      1. The RequestParam annotation
      2. The RequestBody annotation
      3. The PathVariable annotation
    6. Handling Interceptors
    7. Handling Response
      1. Response as an instance of ModelAndView
      2. Using @ResponseBody annotation
    8. Creating a RESTful web service
    9. Dockerizing a Spring Boot application
    10. Summary
  3. Preparing the Spring Web Development Environment
    1. Installing the Java SDK
    2. Installing/configuring Maven
    3. Installing the Eclipse IDE
      1. Import the existing Maven project in Eclipse
      2. Creating a new Maven project in Eclipse 
    4. Installing/configuring the Apache Tomcat server
      1. Adding/configuring Apache Tomcat in Eclipse
    5. Installing/configuring the MySQL database
      1. Installing/configuring the MySQL server 
      2. Using the MySQL connector
      3. Connecting to the MySQL database from a Java class
    6. Introduction to Docker
      1. What are Docker containers?
        1. What are real-world containers good for?
        2. How do Docker containers relate to real-world containers?
        3. Docker containers
      2. What are the key building blocks of Dockers containers?
      3. Installing Docker
    7. Setting up the development environment using Docker compose
      1. What is Docker compose?
      2. Docker Compose Script for setting up the Dev Environment
        1. Setting up the Tomcat 8.x as a container service
        2. Setting up MySQL as a container service
        3. Docker compose script to set up the development environment
    8. Summary
  4. Data Access Layer with Spring and Hibernate
    1. An introduction to Hibernate
    2. Setting up Hibernate with Spring
      1. Setting up data source information in the application.properties file
      2. Using annotations to wire a SessionFactory bean
        1. Configure bean definitions
        2. Autowire SessionFactory in DAOs
    3. Design domain objects and database tables
      1. User
    4. Introduction to NamedQuery and Criteria
      1. What is NamedQuery?
      2. What is Criteria?
    5. Common Hibernate operations
      1. Data retrieval
      2. Save/persist operation
      3. Update/merge operation
        1. The saveOrUpdate operation
    6. Transaction management
      1. Declarative transaction management
    7. Summary
  5. Testing and Running Spring Web App
    1. How to run the Spring Boot app 
    2. Introduction to unit testing fundamentals
      1. What is unit testing?
      2. Why write unit tests?
      3. Unit testing naming conventions
    3. Introduction to JUnit 5
      1. Architectural building blocks of JUnit 5
      2. Setting up and running JUnit tests
    4. Mocking dependencies using Mockito
      1. Getting set up with Mockito
      2. Introduction to mocking techniques
    5. Unit testing controllers, services, and DAOs
      1. Unit tests for controllers
      2. Unit tests for Services
      3. Unit tests for DAO components
    6. Summary
  6. Securing Web App with Spring Security
    1. Introduction to Spring Security
      1. Spring Security high level architecture
        1. Spring Security architecture - core building blocks
        2. Spring Security architecture - authentication
        3. Spring  Security architecture - authorization
      2. Setting up Spring Security
    2. Handling the login authentication
    3. CSRF protection for API requests
      1. CSRF prevention technique for the Angular app
      2. CSRF prevention technique for the Spring app
    4. Handling the logout request
    5. OAuth2 for authentication/authorization
      1. Introduction to OAuth2-based authentication & authorization
      2. Spring Security and OAuth2 authentication
        1. OAuth2 Implementation for Spring Web App
        2. OAuth2 Implementation for Angular App
          1. Acquiring access token
          2. Accessing resources using access token
    6. Summary
  7. Getting Started with Angular
    1. Introduction to Angular
    2. How is Angular different from AngularJS?
      1. AngularJS - The MVC way of building UI apps
      2. Angular - The Component Way of Building Web Apps
    3. Setting up the Angular development environment
    4. TypeScript fundamentals
    5. Forms
      1. Template-driven forms
      2. Reactive forms
    6. Pipes
    7. Directives
      1. Structural directives
      2. Attribute directives
    8. Server communication
    9. Bootstrapping an Angular app
    10. Best practices
    11. Summary
  8. Creating SPA with Angular and Spring 5
    1. Introduction to routing
    2. Configuring Route definitions
    3. RouterLink for navigation
      1. What is RouterLink?
      2. What is ActivatedRoute?
    4. Route Guards for access control
    5. Routing configuration design patterns
      1. Routing within AppModule
      2. Routing as a separate module at the app root level
      3. Routing within feature modules
    6. Creating a single page app (SPA) 
      1. Lean root module
      2. Features as separate modules
        1. Auth module
        2. Doctor module
      3. Route Guards for controlled access
    7. Debugging Angular app
      1. Debugging Angular app using Firefox and Chrome
      2. Debugging Angular app using Augury
    8. Summary
  9. Unit Testing with Angular Apps
    1. Introduction to unit testing
    2. Unit testing tools for Angular apps
      1. Jasmine
        1. Karma
        2. Protractor 
        3. Angular testing utilities 
    3. Setting up the unit test environment
    4. Angular unit testing building blocks
    5. Unit testing strategies
    6. Unit testing the components
      1. Unit testing a component with an external template
      2. Unit testing a component with one or more dependencies
      3. Unit testing a component with an async service
        1. Component-under-test - DoctorListComponent
        2. External service - DoctorService
        3. Unit test for DoctorListComponent
      4. Unit testing a routed component
        1. Test doubles for Router and ActivatedRoute
        2. Unit test for a routed component
    7. Unit testing the services
      1. Service under test - DoctorService
      2. Unit test for DoctorService
    8. Summary
  10. Securing an Angular App
    1. Common web application security vulnerabilities
      1. What is Cross-Site Scripting (XSS)?
      2. What is Cross-Site Script Inclusion (XSSI)?
      3. What is Cross-Site Request Forgery (CSRF/XSRF)?
    2. Securing an app from XSS
      1. Displaying trusted HTML values
        1. The Custom SecurityBypass pipe
    3. Securing an app from XSSI
    4. Securing app from CSRF/XSRF
    5. Best practices
    6. Summary
  11. Integrating Angular App with Spring Web APIs
    1. Building RESTful Spring web APIs
    2. Configure Spring app for CORS
    3. Key aspects of Angular data services
      1. Promise and Observable responses
        1. Promise for asynchronous data exchange
        2. Observable for asynchronous data exchange
    4. Building Angular services for RESTful integration
      1. Invoking server APIs using the Angular HTTP service
        1. Consuming RESTful Spring APIs using the HTTP service
        2. Posting to RESTful Spring APIs using the HTTP service
      2. Invoking  server APIs using the Angular HttpClient service
    5. Example of consuming RESTful Spring web APIs 
      1. Spring RESTful API for user login
      2. Custom Angular component for managing login view
      3. Custom Angular service for serving login functionality
    6. Summary
  12. Deploying the Web Application
    1. Introduction to CI and CD
    2. Setting up Jenkins and GitLab
      1. Setting up Jenkins
      2. Setting up GitLab
      3. Setting up GitLab and Jenkins using Docker Compose
    3. Configuring GitLab as a code repository
    4. Creating Jenkins jobs for CI
    5. Configuring Jenkins and GitLab for CI/CD 
      1. Configuring webhooks in GitLab
      2. Configuring Jenkins for automated build triggers
    6. Configuring Jenkins jobs for CD
    7. Deploying Angular app in production
      1. Angular app deployed on separate server
      2. Angular app deployed on Spring app server
    8. Summary

Product information

  • Title: Building Web Apps with Spring 5 and Angular
  • Author(s): Ajitesh Shukla
  • Release date: August 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787284661