售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Copyright
Mastering Spring 5.0
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Evolution to Spring Framework 5.0
Spring Framework
Problems with EJB
Why is Spring Framework popular?
Simplified unit testing
Reduction in plumbing code
How does Spring Framework do this magic?
Architectural flexibility
Keep up with changing times
Spring modules
Spring Core Container
Cross-cutting concerns
Web
Business
Data
Spring Projects
Spring Boot
Spring Cloud
Spring Data
Spring Batch
Spring Security
Spring HATEOAS
New features in Spring Framework 5.0
Baseline upgrades
JDK 9 runtime compatibility
Usage of JDK 8 features in Spring Framework code
Reactive programming support
Functional web framework
Java modularity with Jigsaw
Kotlin support
Dropped features
Spring Boot 2.0 new features
Summary
Dependency Injection
Understanding dependency injection
Understanding dependencies
The Spring IoC container
Defining beans and wiring
Creating a Spring IoC container
Java configuration for the application context
A quick review
Launching the application context with Java configuration
The console log
The XML configuration for the application context
Defining the XML Spring configuration
Launching an application context with the XML configuration
Writing JUnit using the Spring context
Unit testing with mocks
Container managed beans
Dependency injection types
The setter injection
The constructor injection
Constructor versus setter injection
Spring bean scopes
Java versus XML configuration
The @Autowired annotation in depth
The @Primary annotation
The @Qualifier annotation
Other important Spring annotations
Exploring Contexts and dependency injection
An example of CDI
Summary
Building a Web Application with Spring MVC
Java web application architecture
Model 1 architecture
Model 2 architecture
Model 2 Front Controller architecture
Basic flows
Basic setup
Adding dependency for Spring MVC
Adding DispatcherServlet to web.xml
Creating Spring context
Flow 1 - Simple controller flow without View
Creating a Spring MVC controller
Running the web application
Unit testing
Setting up the Controller to test
Writing the Test method
Flow 2 - Simple controller flow with a View
Spring MVC controller
Creating a View - a JSP
View resolver
Unit testing
Setting up the Controller to test
Writing the Test method
Flow 3 - Controller redirecting to a View with Model
Spring MVC controller
Creating a View
Unit testing
Setting up the Controller to test
Writing the Test method
Flow 4 - Controller redirecting to a View with ModelAndView
Spring MVC controller
Creating a View
Unit testing
Flow 5 - Controller redirecting to a View with a form
Creating a command or form backing object
The Controller method to show the form
Creating the View with a form
Controller get method to handle form submit
Unit testing
Flow 6 - Adding validation to the previous flow
Hibernate Validator dependency
Simple validations on the bean
Custom validations
Unit testing
Controller setup
The Test method
An overview of Spring MVC
Important features
How it works
Important concepts behind Spring MVC
RequestMapping
Examples of request mapping
Example 1
Example 2
Example 3
Request Mapping methods - supported method arguments
RequestMapping methods - supported return types
View resolution
Configuring JSP view resolver
Configuring Freemarker
Handler mappings and Interceptors
Defining a HandlerInterceptor
Mapping HandlerInterceptor to handlers
Model attributes
Session attributes
Putting an attribute in the session
Reading an attribute from the session
Removing an attribute from the session
InitBinders
The @ControllerAdvice annotation
Spring MVC - advanced features
Exception handling
Common exception handling across controllers
The error view
Specific exception handling in a Controller
Internationalization
Message bundle setup
Configuring a SessionLocaleResolver
Configuring a CookieLocaleResolver
Integration testing Spring controllers
Serving static resources
Exposing static content
Caching static content
Enabling GZip compression of static content
Integrating Spring MVC with Bootstrap
Bootstrap WebJar as Maven dependency
Configure Spring MVC resource handler to deliver WebJar static content
Using Bootstrap resources in JSP
Spring Security
Adding Spring Security dependency
Configuring a filter to intercept all requests
Logout
Summary
Evolution toward Microservices and Cloud-Native Applications
Typical web application architecture with Spring
Web layer
Web application - rendering an HTML View
RESTful services
Business layer
Data layer
Integration layer
Cross-cutting concerns
Problems solved by Spring
Loose coupling and testability
Plumbing code
Lightweight architecture
Architecture flexibility
Simplified implementation of cross-cutting concerns
Design patterns for free
Application development goals
Speed
Safety
Reliability
Availability
Security
Performance
High resilience
Scalability
Challenges with monolithic applications
Long release cycles
Difficult to scale
Adapting new technologies
Adapting new methodologies
Adapting modern development practices
Understanding microservices
What is a microservice?
The microservice architecture
Microservice characteristics
Small and lightweight microservices
Interoperability with message-based communication
Capability-aligned microservices
Independently deployable units
Stateless
Automated build and release process
Event-driven architecture
Approach 1 - sequential approach
Approach 2 - event-driven approach
Independent teams
Microservice advantages
Faster time to market
Technology evolution
Availability and scaling
Team dynamics
Microservice challenges
Increased need for automation
Defining the boundaries of subsystems
Visibility and monitoring
Fault tolerance
Eventual consistency
Shared capabilities (enterprise level)
Increased need for operations teams
Cloud-Native applications
Twelve-Factor App
Maintain one code base
Dependencies
Config
Backing services
Build, release, run
Stateless
Port binding
Concurrency
Disposability
Environment parity
Logs as event streams
No distinction of admin processes
Spring projects
Spring Boot
Spring Cloud
Summary
Building Microservices with Spring Boot
What is Spring Boot?
Building a quick prototype for a microservice
Primary goals
Nonfunctional features
Spring Boot Hello World
Configure spring-boot-starter-parent
spring-boot-starter-parent
Configure pom.xml with the required starter projects
Understanding starter projects
Configuring spring-boot-maven-plugin
Creating your first Spring Boot launch class
SpringApplication class
The @SpringBootApplication annotation
Running our Hello World application
Auto-configuration
Starter projects
What is REST?
First REST service
Simple method returning string
Unit testing
Integration testing
Simple REST method returning an object
Executing a request
Unit testing
Integration testing
Get method with path variables
Executing a request
Unit testing
Integration testing
Creating a todo resource
Request methods, operations, and URIs
Beans and services
Retrieving a Todo list
Executing the service
Unit testing
Integration testing
Retrieving details for a specific Todo
Executing the service
Unit testing
Integration testing
Adding a Todo
Postman
Executing the POST service
Unit testing
Integration testing
Spring Initializr
Creating your first Spring Initializr project
pom.xml
FirstSpringInitializrApplication.java class
FirstSpringInitializrApplicationTests class
A quick peek into auto-configuration
Summary
Extending Microservices
Exception handling
Spring Boot default exception handling
Nonexistent resource
Resource throwing an exception
Throwing a custom exception
Customizing the exception message
Response status
HATEOAS
Sending HATEOAS links in response
Spring Boot starter HATEOAS
Validation
Enabling validation on the controller method
Defining validations on the bean
Unit testing validations
Documenting REST services
Generating a Swagger specification
Swagger UI
Customizing Swagger documentation using annotations
Securing REST services with Spring Security
Adding Spring Security starter
Basic authentication
Integration testing
Unit testing
OAuth 2 authentication
High-level flow
Implementing OAuth 2 authentication for our service
Setting up authorization and resource servers
Executing OAuth requests
Obtaining an access token
Executing the request using the access token
Integration test
Internationalization
Caching
Spring-boot-starter-cache
Enabling caching
Caching data
JSR-107 caching annotations
Auto-detection order
Summary
Advanced Spring Boot Features
Externalised configuration
Customizing frameworks through application.properties
Logging
Embedded server configuration
Spring MVC
Spring starter security
Data Sources, JDBC and JPA
Other configuration options
Custom properties in application.properties
Configuration properties - type-safe Configuration Management
Profiles
Profiles-based Bean configuration
Other options for application configuration values
YAML configuration
Embedded servers
Switching to Jetty and Undertow
Building a WAR file
Developer tools
Live reload
Spring Boot Actuator
HAL Browser
Configuration properties
Environment details
Health
Mappings
Beans
Metrics
Auto-configuration
Debugging
Deploying an application to Cloud
Cloud Foundry
Summary
Spring Data
Background - data stores
Spring Data
Spring Data Commons
Repository
The CrudRepository interface
The PagingAndSortingRepository interface
Spring Data JPA
Spring Data JPA example
New project with Starter Data JPA
Entities
The SpringBootApplication class
Populating some data
A simple repository
Unit test
The CrudRepository interface
Unit test
The PagingAndSortingRepository interface
Unit tests
Query methods
Queries
Named Parameters
Named Query
Native query
Spring Data Rest
The GET method
The POST method
The search resource
Big Data
MongoDB
Unit test
Summary
Spring Cloud
Introducing Spring Cloud
Spring Cloud Netflix
Demo microservices setup
Microservice A
Service consumer
Ports
Centralized microservice configuration
Problem statement
Solution
Options
Spring Cloud Config
Implementing Spring Cloud Config Server
Setting up Spring Cloud Config Server
Connecting Spring Cloud Config Server to a local Git repository
Creating an environment-specific configuration
Spring Cloud Config Client
Spring Cloud Bus
The need for Spring Cloud Bus
Propogating configuration changes using Spring Cloud Bus
Implementation
Declarative REST Client - Feign
Load balancing
Ribbon
Implementation
The Name server
Limitations of hard coding microservice URLs
Workings of Name server
Options
Implementation
Setting up a Eureka Server
Registering microservices with Eureka
Connecting the service consumer microservice with Eureka
API Gateways
Implementing client-side load balancing with Zuul
Setting up a new Zuul API Gateway Server
Zuul custom filters
Invoking microservices through Zuul
Configuring service consumer to use Zuul API gateway
Distributed tracing
Distributed tracing options
Implementing Spring Cloud Sleuth and Zipkin
Integrating microservice components with Spring Cloud Sleuth
Setting up Zipkin Distributed Tracing Server
Integrating microservice components with Zipkin
Hystrix - fault tolerance
Implementation
Summary
Spring Cloud Data Flow
Message-based asynchronous communication
Complexities of asynchronous communication
Spring projects for asynchronous messages
Spring Integration
Spring Cloud Stream
Spring Cloud Data Flow
Spring Cloud Stream
Spring Cloud Stream architecture
Event processing - stock trading example
Model for stock trading example
The source application
Processor
Sink
Spring Cloud Data Flow
High-level architecture
Implementing Spring Cloud Data Flow
Setting up Spring Cloud Data Flow server
Setting up Data Flow Shell project
Configuring the apps
Configuring the stream
Deploying the stream
Log messages - setting up connections to the message factory
Log messages - the flow of events
Spring Cloud Data Flow REST APIs
Spring Cloud Task
Summary
Reactive Programming
The Reactive Manifesto
Characteristics of Reactive Systems
Reactive use case - a stock price page
The traditional approach
The reactive approach
Comparison between the traditional and reactive approaches
Reactive programming in Java
Reactive streams
Reactor
Mono
Flux
Spring Web Reactive
Creating a project using Spring Initializr
Creating a Reactive Controller
Creating an HTML view
Launching SpringReactiveExampleApplication
Reactive databases
Integrating Spring Boot Reactive MongoDB Starter
Creating a model object - a stock document
Creating a ReactiveCrudRepository
Initialising stock data using the Command Line Runner
Creating Reactive methods in Rest Controller
Updating the view to subscribe to the event stream
Launching SpringReactiveExampleApplication
Summary
Spring Best Practices
Maven standard directory layout
Layered architecture
Recommended practices
Separate API and impl for important layers
Exception handling
Spring's approach to exception handling
The recommended approach
Keeping your Spring configuration light
Using the basePackageClasses attribute in ComponentScan
Not using version numbers in schema references
Preferring constructor injection over setter injection for mandatory dependencies
Managing dependency versions for Spring Projects
Unit testing
The business layer
Web layer
The data layer
Other best practices
Integration testing
Spring Session
Example
Adding dependencies for Spring Session
Configuring Filter to replacing HttpSession with Spring Session
Enabling filtering for Tomcat by extending AbstractHttpSessionApplicationInitializer
Caching
Adding the Spring Boot Starter Cache dependency
Adding caching annotations
Logging
Logback
Log4j2
Framework independent configuration
Summary
Working with Kotlin in Spring
Kotlin
Kotlin versus Java
Variables and type inference
Variables and immutability
Type system
Functions
Arrays
Collections
No checked exceptions
Data class
Creating a Kotlin project in Eclipse
Kotlin plugin
Creating a Kotlin project
Creating a Kotlin class
Running a Kotlin class
Creating a Spring Boot project using Kotlin
Dependencies and plugins
Spring Boot application class
Spring Boot application test class
Implementing a REST service using Kotlin
Simple method returning a string
Unit testing
Integration testing
Simple REST method returning an object
Executing a request
Unit testing
Integration testing
Get method with path variables
Executing a request
Unit testing
Integration testing
Summary
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜