2-3 Creating Spring beans using static and instance factory methods
2-4 Constructor-based DI
2-5 Passing configuration details to beans
2-6 Bean scopes
2-7 Summary
3-1 Introduction
3-2 Bean definition inheritance
3-3 Constructor argument matching
3-4 Configuring different types of bean properties and constructor arguments
CustomBooleanEditor
CustomNumberEditor
CharacterEditor
CustomDateEditor
PropertiesEditor
java.util.ArrayList
java.util.LinkedHashSet
java.util.LinkedHashMap
3-5 Built-in property editors
3-6 Registering property editors with the Spring container
3-7 Concise bean definitions with p and c namespaces
3-8 Spring’s util schema
3-9 FactoryBean interface
DatabaseEventSender
MessagingEventSender
WebServiceEventSender
3-10 Modularizing bean configuration
3-11 Summary
4-1 Introduction
4-2 Inner beans
4-3 Controlling the bean initialization order with depends-on attribute
4-4 Singleton- and prototype-scoped bean’s dependencies
4-5 Obtaining new instances of prototype beans inside singleton beans
4-6 Autowiring dependencies
4-7 Summary
5-1 Introduction
5-2 Customizing bean’s initialization and destruction logic
5-3 Interacting with newly created bean instances using a BeanPostProcessor
5-4 Modifying bean definitions using BeanFactoryPostProcessor
5-5 Summary
6-1 Introduction
6-2 Identifying Spring beans with @Component
annotation
assignable
aspectj
regex
custom
6-3 @Autowired - autowiring dependencies by type
6-4 @Qualifier – autowiring dependencies by name
6-5 JSR 330’s @Inject and @Named annotations
6-6 JSR 250’s @Resource annotation
6-7 @Scope, @Lazy, @DependsOn and @Primary annotations
@Scope
@Lazy
@DependsOn
@Primary
6-8 Simplifying configuration of annotated bean classes using @Value annotation
6-9 Validating objects using Spring’s Validator interface
6-10 Specifying constraints using JSR 380 (Bean Validation 2.0) annotations
@NotNull
@Min
@Max
@NotBlank
@Size
6-11 Bean definition profiles
6-12 Summary
7-1 Introduction
7-2 Configuring beans using @Configuration and @Bean annotations
autowire
initMethod
destroyMethod
7-3 Injecting bean dependencies
7-4 Configuring the Spring container
7-5 Lifecycle callbacks
7-6 Importing Java-based configurations
7-7 Additional topics
7-8 Summary
8-1 Introduction
8-2 MyBank application’s requirements
8-3 Developing the MyBank application using Spring’s JDBC module
8-4 Developing the MyBank application using Hibernate
8-5 Transaction management using Spring
8-6 Developing the MyBank application using Java-based configuration
8-7 Summary
9-1 Introduction
9-2 Core concepts and interfaces
9-3 Spring Data JPA
9-4 Creating queries using Querydsl
9-5 Query by Example (QBE)
9-6 Spring Data MongoDB
9-7 Summary
10-1 Introduction
10-2 MyBank application’s requirements
10-3 Sending JMS messages
10-4 Receiving JMS messages
10-5 Sending emails
10-6 Task scheduling and asynchronous execution
10-7 Caching
10-8 Running the MyBank application
10-9 Summary
11-1 Introduction
11-2 A simple AOP example
11-3 Spring AOP framework
11-4 Pointcut expressions
access-modifier-pattern
return-type-pattern
declaring-type-pattern
method-name-pattern
method-param-pattern
throws-pattern
11-5 Advice types
11-6 Spring AOP - XML schema-style
11-7 Summary
12-1 Introduction
12-2 Directory structure of sample web projects
12-3 Understanding the ‘Hello World’ web application
HelloWorldController.java
helloworld.jsp
myapp-config.xml
web.xml
12-4 DispatcherServlet – the front controller
Bean scope
request
session
application
websocket
12-5 Developing controllers using @Controller and @RequestMapping annotations
12-6 MyBank web application’s requirements
12-7 Spring Web MVC annotations - @RequestMapping and @RequestParam
12-8 Validation
12-9 Handling exceptions using @ExceptionHandler annotation
12-10 Loading root web application context XML file(s)
12-11 Summary
13-1 Introduction
13-2 Adding and retrieving model attributes using @ModelAttribute annotation
13-3 Caching model attributes using @SessionAttributes annotation
13-4 Data binding support in Spring
WebBindingInitializer
13-5 Validation support in Spring
@NotNull
@Min
@Max
@Size
@Email
13-6 Spring’s form tag library
13-7 Configuring web applications using Java-based configuration
13-8 Summary
14-1 Introduction
14-2 Fixed deposit web service
14-3 Implementing a RESTful web service using Spring Web MVC
GET
/fixedDeposits
GET
POST
/fixedDeposits
PUT
DELETE
GET
getFixedDepositList
GET
getFixedDeposit
POST
openFixedDeposit
PUT
editFixedDeposit
DELETE
closeFixedDeposit
Specifying HTTP response using ResponseEntity
Specifying HTTP response using HttpServletResponse
Binding returned value of a method to HTTP response body using @ResponseBody
Binding HTTP request body to a method parameter using @RequestBody
Setting HTTP response status using @ResponseStatus
Handling exceptions using @ExceptionHandler
14-4 Accessing RESTful web services using RestTemplate and WebClient
StringHttpMessageConverter
FormHttpMessageConverter
MappingJackson2HttpMessageConverter
MarshallingHttpMessageConverter
14-6 @PathVariable and @MatrixVariable annotations
14-7 Summary
15-1 Introduction
15-2 Pre- and post-processing requests using handler interceptors
15-3 Internationalizing using resource bundles
15-4 Asynchronously processing requests
15-5 Type conversion and formatting support in Spring
15-6 File upload support in Spring Web MVC
15-7 Summary
16-1 Introduction
16-2 Security requirements of the MyBank web application
16-3 Securing MyBank web application using Spring Security
spring-security-core
spring-security-web
spring-security-config
spring-security-taglibs
spring-security-acl
16-4 MyBank web application - securing FixedDepositDetails instances using Spring Security’s ACL module
16-5 Configuring Spring Security using Java-based configuration approach
16-6 Summary
17-1 Introduction
17-2 Imperative vs functional style
17-3 Lambda expressions
17-4 Creating simple functions and higher-order functions
Function
BiFunction
Consumer
BiConsumer
17-5 Stream API
17-6 Method references
17-7 Summary
18-1 Introduction
18-2 Reactive Streams
18-3 Hot and cold publishers
18-4 Backpressure
18-5 Summary
19-1 Introduction
19-2 Reactive types defined by Reactor and RxJava 2
19-3 Developing the data access layer using Spring Data
19-4 Developing the web layer using Spring WebFlux
19-5 Securing a WebFlux application
19-6 Summary
A-1 Downloading and installing MongoDB database
A-2 Connecting to the MongoDB database
B-1 Downloading and installing Eclipse IDE and Tomcat 9
B-2 Importing a sample project into Eclipse IDE
B-3 Configuring Eclipse IDE with Tomcat 9 server
B-4 Deploying a web project on Tomcat 9 server
Getting started with Spring Framework
(covers
Fourth Edition
Getting started with Spring Framework is a hands-on guide to begin
developing applications using Spring Framework. This book is meant for
Java developers with little or no knowledge of Spring Framework. Getting
started with Spring Framework, Fourth Edition has been updated to
reflect changes in Spring 5 and includes new chapters - Functional
programming with Java
lambda expressions, higher-order
functions, Stream API and method references), Reactive programming with
RxJava 2 (covers Reactive Streams specification and RxJava 2), and
Developing reactive applications using Spring (shows a reactive RESTful
web service that uses MongoDB’s reactive database driver, Spring Data
MongoDB’s reactive support to build the data access layer, Spring WebFlux
module to build the web layer, and Spring Security’s reactive support to
secure the web service).
The examples that accompany this book are based on Spring 5.0.1. You can
download the examples (consisting of 85 sample projects) described in this
book from the following GitHub project: https://github.com/getting-started-
with-spring/4thEdition
Chapter 1 – Introduction to Spring Framework
Chapter 2 – Spring Framework basics
Chapter 3 - Configuring beans
Chapter 4 - Dependency injection
Chapter 5 - Customizing beans and bean definitions
Chapter 6 - Annotation-driven development with Spring
Chapter 7 – Java-based container configuration
Chapter 8 - Database interaction using Spring
Chapter 9 – Spring Data
Chapter 10 - Messaging, emailing, asynchronous method
execution, and caching using Spring
Chapter 11 - Aspect-oriented programming
Chapter 12 – Spring Web MVC basics
Chapter 13 – Validation and data binding in Spring Web
MVC
Chapter 14 – Developing RESTful web services using
Spring Web MVC
Chapter 15 – More Spring Web MVC –
internationalization, file upload and asynchronous request
processing
Chapter 16 – Securing applications using Spring Security
Chapter 17 – Functional programming with Java (New)
Chapter 18 – Reactive programming with RxJava 2 (New)
Chapter 19 - Developing reactive RESTful web services
using Spring WebFlux, Spring Data and Spring Security
(New)
Appendix A – Downloading and installing MongoDB
database
Appendix B – Importing and deploying sample projects in
Eclipse IDE
Ashish Sarin, J Sharma
Table of contents
Preface
How to use this book ?
Download sample projects
Import sample projects into your Eclipse IDE
Refer to code examples
Conventions used in this book
Feedback and questions
About the authors
Chapter 1 – Introduction to Spring Framework
1-1 Introduction
1-2 Spring Framework modules
1-3 Spring IoC container
1-4 Benefits of using Spring Framework
Consistent approach to managing local and global transactions
Declarative transaction management
Security
JMX (Java Management Extensions)
JMS (Java Message Service)
Caching
1-5 A simple Spring application
Identifying application objects and their dependencies
Creating POJO classes corresponding to identified application objects
Creating the configuration metadata
Creating an instance of Spring container
Access beans from the Spring container
1-6 What’s new in Spring Framework 5 ?
1-7 Frameworks built on top of Spring
1-8 Summary
Chapter 2 – Spring Framework basics
2-1 Introduction
2-2 Programming to interfaces design principle
Spring’s support for ‘programming to interfaces’ design approach
2-3 Creating Spring beans using static and instance factory methods
Instantiating beans via static factory methods
Instantiating beans via instance factory methods
2-4 Constructor-based DI
Revisiting setter-based DI
Constructor-based DI
2-5 Passing configuration details to beans
2-6 Bean scopes
Singleton
Prototype
Choosing the right scope for your beans
2-7 Summary
Chapter 3 - Configuring beans
3-1 Introduction
3-2 Bean definition inheritance
MyBank – Bean definition inheritance example
What gets inherited ?
3-3 Constructor argument matching
Passing simple values and bean references using
element
Constructor argument matching based on type
Constructor argument matching based on name
3-4 Configuring different types of bean properties and constructor
arguments
Built-in property editors in Spring
Specifying values for different collection types
Specifying values for arrays
Default implementations corresponding to , and
4-4 Singleton- and prototype-scoped bean’s dependencies
Singleton bean’s dependencies
Prototype bean’s dependencies
4-5 Obtaining new instances of prototype beans inside singleton beans
ApplicationContextAware interface
element
element
4-6 Autowiring dependencies
byType
constructor
byName
default / no
Making beans unavailable for autowiring
Autowiring limitations
4-7 Summary
Chapter 5 - Customizing beans and bean definitions
5-1 Introduction
5-2 Customizing bean’s initialization and destruction logic
Making Spring invoke cleanup method specified by the destroy-method
attribute
Cleanup methods and prototype beans
Specifying default bean initialization and destruction methods for all
beans
InitializingBean and DisposableBean lifecycle interfaces
JSR 250’s @PostConstruct and @PreDestroy annotations
5-3 Interacting with newly created bean instances using a
BeanPostProcessor
BeanPostProcessor example – Validating bean instances
BeanPostProcessor example – Resolving bean dependencies
BeanPostProcessor behavior for FactoryBeans
RequiredAnnotationBeanPostProcessor
DestructionAwareBeanPostProcessor
5-4 Modifying bean definitions using BeanFactoryPostProcessor
BeanFactoryPostProcessor example
PropertySourcesPlaceholderConfigurer
PropertyOverrideConfigurer
5-5 Summary
Chapter 6 – Annotation-driven development with Spring
6-1 Introduction
6-2 Identifying Spring beans with @Component
6-3 @Autowired - autowiring dependencies by type
6-4 @Qualifier – autowiring dependencies by name
Autowiring beans using qualifiers
Creating custom qualifier annotations
6-5 JSR 330’s @Inject and @Named annotations
Java 8’s Optional type
6-6 JSR 250’s @Resource annotation
6-7 @Scope, @Lazy, @DependsOn and @Primary annotations
@Scope
@Lazy
@DependsOn
@Primary
6-8 Simplifying configuration of annotated bean classes using @Value
annotation
Using Spring Expression Language (SpEL) with @Value annotation
Using @Value annotation at method-level and method-parameter-level
6-9 Validating objects using Spring’s Validator interface
6-10 Specifying constraints using JSR 380 (Bean Validation 2.0)
annotations
JSR 380 support in Spring
What’s new in JSR 380 ?
6-11 Bean definition profiles
Bean definition profiles example
6-12 Summary