Sold to
Spring Boot CheatSheet
robin.424242@[Link]
Essentials
Start Setting Properties
Use the Spring Initializr to bootstrap. Set properties with -D on commandline or in
[Link]
[Link]
Configuration Test
Start application with Uses JUnit, includes Mockito, Hamcrest and more
@SpringBootApplication @RunWith([Link]) : Enabled Spring Test features in JUnit
public class CommentStoreApp {
public static void main(String[] args) @SpringBootTest : Mark as a Spring Boot test; will start full server by default
throws Exception {
[Link]([Link], args); @DataJpaTest : Marks as a Spring Data JPA test and only auto-configures that part
}
}
@WebMvcTest : Marks as a Spring MVC test and only auto-configures that part
@SpringBootApplication is a shortcut annotation for
@MockBean : On TYPE adds Mocks to Context, On FIELD creates and injects Mock for
use in test
@Configuration : Marks class as a config class
@EnableAutoConfiguration : Configure application based on dependencies
@ComponentScan : Scans classpath for Spring Components and auto registers them
Logging Production Features
By default, uses SLF4J with Logback Enable by adding:
private static final Logger LOGGER = <dependency>
[Link]([Link]) <groupId>[Link]</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
[Link]: names the logfile, relative or absolute </dependency>
[Link] : if file is not absolute, path where the logfile is stored Endpoints available under / or /application (Spring Boot 2) Change path with
[Link]-path
[Link]
property
: set log level for application; replace root with your package to fine
grained control /health: shows a health status
/metrics: metrics of your application
/info: put app and build information here
[Link]