Code examples for setting up a Spring Boot application
To better understand what this means, let's look at some source code examples.
We will only look at some small fragments of code here to point out the main features. For a fully working example, you’ll have to wait until the next chapter!
The magic @SpringBootApplication annotation
The convention-based autoconfiguration mechanism can be initiated by annotating the application class (that is, the class that contains the static main
method) with the @SpringBootApplication
annotation. The following code shows this:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
The following functionality will be provided by this annotation:
- It enables component scanning, that is, looking for Spring components and configuration classes in the package of the application class and all its subpackages.
- The application class itself...