0% found this document useful (0 votes)
423 views

Spring Boot 2 Cheat Sheet

This document provides a cheat sheet on Spring Boot 2. It outlines what Spring Boot is, its key features, how to get started with a quickstart project, best practices for code structure, configuration options, building production jars, available starters, and how to run the code. It also provides pointers on where to go for more in-depth information on Spring Boot and Spring Framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
423 views

Spring Boot 2 Cheat Sheet

This document provides a cheat sheet on Spring Boot 2. It outlines what Spring Boot is, its key features, how to get started with a quickstart project, best practices for code structure, configuration options, building production jars, available starters, and how to run the code. It also provides pointers on where to go for more in-depth information on Spring Boot and Spring Framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SPRING BOOT 2 CHEAT SHEET

Spring Boot 2.1.x - Date : November 2018


BEST PRACTICES
WHAT IS SPRING BOOT ? Don't use the **default** package. Prefer using
the Java convention *com.example.project*
Built on top of a lot of Spring Projects
(https://spring.io) Code structure
Opinionated configuration
Wide ecosystem com

Start a project faster with no configuration + example

| + project

| | - MyApp.java

FEATURES | | |

| | + player

Bootstrap class SpringApplication | | | - Player.java

| | | - PlayerService.java
Default logger (@see spring-jcl)
FailureAnalyzers : friendly failure report
Application Events on Listeners Configuration
Choose the right ApplicationContext
Accessing application arguments Properties files in folder src/main/resources/ are loaded
Control application exit code automatically
YAML : **/application*.yml or
QUICKSTART **/application*.yaml
Properties : **/application*.properties
<parent>

<groupId>org.springframework.boot</groupId>
Auto-configuration
<artifactId>spring-boot-starter-
parent</artifactId>
Enabled by @SpringBootApplication or
<version>2.1.0.RELEASE</version>
@EnableAutoConfiguration
</parent>
Spring Boot scans all libs on the classpath and auto-

<dependencies>

configures them (if you didn't manually)


<dependency>

<groupId>org.springframework.boot</groupId>
Display Spring Boot Autoconfigure report
<artifactId>spring-boot-starter</artifactId>

</dependency>
java -jar myapp.jar --debug
</dependencies>
Disabling an auto-configuration class with Java conf
@SpringBootApplication

public class MyApp {


@EnableAutoConfiguration(exclude=

{DataSourceAutoConfiguration.class})
public static void main(String[] args) {

SpringApplication.run(MyApp.class, args);

Disabling an auto-configuration class with properties


} spring.autoconfigure.exclude= \

org.springframework.boot.autoconfigure.XXXX

groupe-sii.github.io/cheat-sheets www.groupe-sii.com blog.groupe-sii.com


SPRING BOOT 2 CHEAT SHEET
BUILD A PRODUCTION JAR STARTERS
Maven Official starters : spring-boot-starter-*
Application starters
<build>

<plugins>

<plugin>
Name Function
<groupId>org.springframework.boot</groupId>
Web applications using Spring MVC
<artifactId>spring-boot-maven- web
plugin</artifactId>
(Tomcat embedded)
</plugin>
Spring test using JUnit, Hamcrest
</plugins>
test
</build> and Mockito
Secured services with Spring
security
Gradle Security
WebFlux applications using Spring
plugins {
webflux
id 'org.springframework.boot' version Framework’s Reactive Web
'2.1.0.RELEASE'
WebSocket applications using
} websocket
Spring Framework’s WebSocket
Actuator Configured resources to use Spring
data-jdbc
Data JDBC
Production ready features threw HTTP or JMX data- Configured resources to use Spring
<dependency>

mongodb Data JPA with Hibernate


<groupId>org.springframework.boot</groupId>
Web applications using Spring Data
<artifactId>spring-boot-starter- data-rest
actuator</artifactId>

repositories over REST


</dependency> Production ready features using
actuator Spring's Actuator (monitor and
RUNNING THE CODE manage)
Technical starters
Standalone
Name Function
java -jar target/myapplication-0.0.1-SNAPSHOT.jar
jetty Using Jetty over the default Tomcat
Standalone with remote debug Using Log4j2 for logging over the
log4j2
default Logback
java -Xdebug \

Using Undertow over the default


-Xrunjdwp:server=y,transport=dt_socket\
undertow
,address=8000,suspend=n -jar target/myapplication- Tomcat
0.0.1-SNAPSHOT.jar

Maven GO DEEPER

mvn spring-boot:run https://spring.io/guides


https://spring.io/projects/spring-framework
Gradle Spring Boot documentation
Spring Core cheat sheet
gradle bootRun

groupe-sii.github.io/cheat-sheets www.groupe-sii.com blog.groupe-sii.com

You might also like