You are on page 1of 2

SPRING BOOT 2 CHEAT SHEET

Spring Boot - Date :

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)
• Opinionated con�guration
• Wide ecosystem com
• Start a project faster with no con�guration + example
| + project
| | - MyApp.java
| | |
| | + player
• Bootstrap class SpringApplication | | | - Player.java
• Default logger (@see spring-jcl) | | | - PlayerService.java
• FailureAnalyzers : friendly failure report
• Application Events on Listeners
• Choose the right ApplicationContext
• Accessing application arguments Properties �les in folder src/main/resources/ are loaded
• Control application exit code automatically

• : **/application*.yml or
**/application*.yaml
• : **/application*.properties
<parent>
<groupId>org.springframework.boot</groupId>
<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> con�gures them ( )
<dependency>
Display Spring Boot Autocon�gure report
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> java -jar myapp.jar --debug
</dependencies>
Disabling an auto-con�guration 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-con�guration 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

Maven O�cial starters : spring-boot-starter-*

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId> Web applications using Spring
<artifactId>spring-boot-maven- MVC (Tomcat embedded)
plugin</artifactId>
</plugin> Spring test using JUnit, Hamcrest
</plugins> and Mockito
</build>
Secured services with Spring
Gradle Security
WebFlux applications using Spring
plugins { Framework’s Reactive Web
id 'org.springframework.boot' version
'2.1.0.RELEASE' WebSocket applications using
} Spring Framework’s WebSocket
Con�gured resources to use
Spring Data JDBC
Production ready features threw HTTP or JMX Con�gured resources to use
Spring Data JPA with Hibernate
<dependency>
<groupId>org.springframework.boot</groupId> Web applications using Spring
<artifactId>spring-boot-starter- Data repositories over REST
actuator</artifactId>
Production ready features using
</dependency>
Spring's Actuator (monitor and
manage)

Standalone

java -jar target/myapplication-0.0.1-SNAPSHOT.jar Using Jetty over the default Tomcat


Using Log4j2 for logging over the
Standalone with remote debug
default Logback
java -Xdebug \ Using Undertow over the default
-Xrunjdwp:server=y,transport=dt_socket\ Tomcat
,address=8000,suspend=n -jar target/myapplication-
0.0.1-SNAPSHOT.jar

Maven
• https://spring.io/guides
mvn spring-boot:run • https://spring.io/projects/spring-framework
• Spring Boot documentation
Gradle • Spring Core cheat sheet

gradle bootRun

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

You might also like