# Spring Framework och Spring Boot

Nivå: advanced | Målgrupp: Java programmerare | Förkunskaper: Stor erfarenhet av att skriva Java kod
https://www.ribomation.se/programmerings-kurser/spring-framework/

Denna kurs lär dig allt du behöver veta för att bli produktiv i ett Spring projekt direkt efter avslutad kurs.

Det finns inget Java ramverk som på ett mer genomgripande sätt förändrat hur vi designar och implementerar
affärs-applikation under de senaste 15 åren som Spring Framework. Via Spring Boot är det lekande lätt att
bygga själv-konfigurerande webb-applikationer.

Denna kurs lär dig allt du behöver veta för att bli produktiv i ett Spring projekt direkt efter avslutad kurs.

- Learn how wire together spring beans using both XML and Java annotations
- Using Spring Boot
- Writing a CLI app using Spring Shell
- Generating an executable (native image) using Graal VM and the Spring Boot build plugin
- Tweak the configuration of Spring apps
- Implementing classic web apps
- Implementing hybrid AJAX based web apps
- Implementing SPA web apps
- Implementing REST controllers
- Accessing databases using both JDBC and JPA

#### Background & History
- Rod Johnson
- The fallacy of EJB
- Why Spring was created
- Properties of Spring
- Spring configuration forms
- The evolution and success of Spring
- When Spring started to crumble on its own weight
- The inception of Spring Boot
- Properties of Spring Boot
- Overview of Spring projects

### The Robostore App
- Purpose
- H2 database
- H2 console
- Source code
- Tweaks

### Fundamentals
#### Class Loading
- Class path
- How the JVM loads a class
- JAR files
- Executable JAR file
- Application JAR file
- WAR file
- Static variables
- Thread local variables

#### Dependency Injection
- Sample payment service
- Usage
- Instantiation
- Obvious problems
- Externalization
- Configuration
- Dependency injection, instead
- Inversion of Control, explained
- Call-backs
- Bean factory
- Scopes
- Life-cycle methods
- Sample Spring app

#### Application Context
- Spring Bean Factory
- Spring Application Context
- Types of app contexts
- Configuration samples
- Using XML
- Using Groovy
- Using Java
- Customizations
- Simple bean tracer
- Using PropertySourcesPlaceholderConfigurer

#### Resources
- What is a Spring resource
- Resource types
- Writeable resources
- Resource loader
- Resource dependency

#### SpEL - Spring Expression Language
- What is SPEL?
- Syntax
- Two syntax forms to keep apart

### Configuration

#### XML Configuration
The classic way of wire an application together.

- Why learn XML configuration
- Basic XML bean syntax
- Setter injection
- Constructor injection
- Bean references
- How to load XML bean files
- Bean scopes in XML
- Configuring factory methods
- Life-cycle call-backs in XML
- Using auto-wiring in XML
- Collection property types

#### Beans from a file (_under the hood_)
- Sample domain classes
- BeanRepository
- PropertiesLoader
- BeanRepositoryImpl
- `register`
- `getBean`
- `instantiate`

#### Java Configuration
The better way of wire an application together.

- What is Java configuration of a Spring app
- Writing a @Configuration class with @Bean methods
- Application context
- Context registration
- Injecting bean dependencies
- Scopes
- Initialization method
- Destruction method
- Life-cycle call-backs

#### @nnotation Configuration
The modern way of wire an application together.

- Writing a @Component class and how it relates to @Configuration and @Bean
- Class-path scanning
- Using the scan() method
- Using @ComponentScan
- Using @Autowired
- Constructor injection
- Using a @Qualifier to select a bean by name
- Spring stereotypes

#### Beans from annotations (_under the hood_)
- Sample domain classes
- Annotations
- BeanRepository
- ClasspathLoader
- `loadClassNames`
- `getBeanClassNames`

### Database Access
#### Brief about JDBC
- History
- Drivers
- JDBC URL
- Connection
- Statements
- Prepared statements
- Queries
- Iterating over a result-set

#### Database Access via Spring JDBC
Using JDBC in Spring with JdbcTemplate and friends.

- Spring JDBC module
- Class JdbcTemplate
- Configuring a DataSource
- DriverManagerDataSource
- Embedded database
- H2 memory db
- H2 file db
- H2 server db
- MySQL / PostgreSQL data sources
- Query for a single value
- Query for a multiple values
- Query for a domain object
- Handle not-found
- Query for a Stream
- Named query parameters
- Usage of NamedParameterJdbcTemplate
- Retrieve an auto-generated primary-key

### Spring Boot
Presentation of Spring Boot and its relation to Spring Framework.
Discussions of concepts such as starter dependencies and autoconfiguration.

#### Spring Boot Overview
- Why Spring Boot was created
- What is Spring Boot more precisely
- Version history
- Spring Framework vs. Spring Boot
- Spring Initializer
- Spring Boot CLI
- Started dependencies
- Auto-configuration

#### Spring Native
- What do we mean with native?
- Graal VM
- What is required to build a native image?
- No dynamic class loading and how to deal with it
- Spring Boot build plugin
- How to build Spring app as a native image (_a.k.a. executable_)
- Example

#### Configuration Properties
Different ways to provide configuration properties.

- What is a configuration property
- Application *.properties file
- Standard Spring properties
- Inject property to field
- Inject group of properties to a bean
- Inject all app properties
- Standard type conversions
- Using YaML (*.yml)
- Override on the command-line
- Override by an environment variable
- Using application profiles
- Profile-dependent property files
- Generate build meta-data
- Generate GIT meta-data

#### Using Lombok
- What is Lombok
- Generate getters & setters
- Generate constructors
- Builders
- Generate toString() method
- Generate equals() & hashCode() methods
- Using @Data to bundle them all
- Using @Value to create an immutable data-class

#### Spring Shell
- What is Spring Shell?
- Getting started
- Simple usage
- @ShellComponent
- @ShellMethod
- @ShellOption
- Printing output using the Terminal bean
- Using the shell builder
- Built-in commands

#### Database access via JPA
How to use Spring JPA and autoconfiguration.

- What is JPA
- What is ORM
- What is JDO
- Spring Data project
- Spring Data JPA
- Starter dependencies
- Configure a data-source
- JNDI data-source
- Connection pool
- Hikari CP
- Entity class
- JPA annotations
- JPA repository interface
- Auto-generated CRUD methods
- Database initialization
- Writing query auto-methods
- Using the @Query annotation
- Repository types
- Pagination
- Populating a database

#### SQL & DB access from annotations (_under the hood_)
- Sample domain classes
- Annotations
- DAO factory
- The _magic_ behind this
- SQL generators
- Column descriptors
- Helper methods
- Handler implementations
- Row mapper

### Spring Web

#### HTTP Concepts
Brief about HTTP and web concepts in order to relate and put into
context of the Spring Web Apps chapters of this course.

- HTTP Request / response
- HTTP operations (methods)
- URI / path
- MIME types
- Response status codes
- Cookies
- Java servlet
- HTTP session
- JSP
- Model-View-Controller (MVC)
- AJAX
- The new fetch API
- REST web services
- REST operations
- Web app architectures
- The classic multi-page app (MPA)
- The hybrid multi-page app (Hybrid)
- The modern single-page app (SPA)

#### Building a classic multi-page web app
Using Spring MVC with HTML views.

- Creating a Spring Boot project
- The Spring Web MVC architecture
- Starter package
- Understanding controllers and views
- URI path composition
- GET actions
- View resolution and mapping
- Path variables
- Query parameters
- Redirection
- Assets files
- Template engines
- Brief about Thymeleaf
- Using Mustache
- Rendering a single object in Mustache
- Rendering a list of objects in Mustache

#### Sending Data
- Form data
- POST actions
- @RequestParam
- Form data bean

#### Building an AJAX hybrid web app
Using Spring MVC with AJAX powered HTML views.

- Creating a Spring Boot project
- Changes of controllers
- Changes of view pages
- Controller-less views
- Sample REST CRUD controller
- JavaScript DAO service

#### Building a single-page web app
Using Spring REST as a microservice.

- Creating a Spring Boot project
- Changes of controllers and views
- Run-time deployment of an SPA client
- External SPA client
- Configuring CORS
- Internal SPA client
- Spring configuration for an internal SPA client
- SPA controller

### Deployment
Best practices for deploying Spring apps.

- Deployment options
- Generating an executable JAR as a microservice
- Generating a WAR for deployment to a servlet container
- Working with configuration profiles
- Brief about database schema migration tools
