Overview:
- Features of Spring Boot
- Spring Boot starters
- Auto configuration
- Bootstrapping an application
- Spring Initializr
- Data access
- Spring MVC
Spring Boot requires only one dependency to get all the basics for web application development up and running:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Includes:
- Spring MVC
- REST
- Tomcat
- Jackson
Spring boot will add most of the libraries needed for testing using also just one dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Includes:
- JUnit
- Mockito
- Hamcrest
- Spring Core
- Spring Test
Another dependency will add everything required for Spring Data JPA with Hibernate:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Includes:
- Hibernate
- Spring Data JPA
- Spring ORM
- Command Line Interface
- Applications using Groovy scripts
- Rapid Prototyping
curl -s "https://get.sdkman.io" | bash
sdk install springboot
spring --version
- Go to this link
- Download and extract spring-boot-cli-2.5.4-bin.zip to a desired location
- Follow the 'INSTALL.txt'-instructions
- Create a SPRING_HOME environment variable
- Add %SPRING_HOME%/bin to the classpath
- (Or just use the 'spring.bat'-file in the bin folder)
spring init fundamentals2
spring init --dependencies=web,data-jpa fundamentals3
spring run app.groovy
- Monitor running application
- Manage via HTTP endpoints or JMX
- Health status, metrics, loggers, audit events, HTTP trace
The parent pom.xml holds pre-configured versions for a lot of dependencies, selected by the Spring team to work well together:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Spring Boot takes a convention over configuration approach.
- Finds JARs on the classpath and auto-configures bean
- DAta source for Hibernate or DispatcherServlet for Spring MVC
- User defined beans take precedence over defaults
- Auto-configuration is applied after user defined beans are registered
Insights:
-
Start application with --debug switch
-
Add a simple property to application.properties
logging.level.org.springframework=DEBUG
-
Use the Spring Boot Actuator
The @SpringBootApplication annotation:
-
@SpringBootConfiguration
Replaces @Configuration and annotates a class af configuration
-
@EnableAutoConfiguration
Tells Spring Boot to configure beans
-
@ComponentScan
Tells Spring Boot to scan current package and subpackages
Different properties for multiple Spring Boot Profiles:
applications-{profile}.properties
-
Persistence Data Store
-
Java Database Connectivity (JDBC)
Connects to DB and executes queries
-
Java Persistence API (JPA)
Abstraction that makes it easy to map Java objects to relational DB (Doesn't 'DO' anything)
-
Hibernate (Persistence Provider, Springs implementation for JPA)
Provides repository support for the JPA
-
Model
Representation of data in te system
-
View
Responsible for displaying data
-
Controller
Directing incoming user requests
- Fragments
- Repeatable chunks of code
- Components reused across pages
- Repackages our JAR / WAR files to be executed
- Runs Spring Boot Application
- Provides built-in dependency resolver
- Manages lifecycle of Spring Boot Application
Options:
- Packaged as a traditional web application in a WAR file
- Standalone application, packaged in executable JAR file