Complete the code to create a Spring Boot application main class.
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.[1](Application.class, args); } }
The SpringApplication.run() method starts the Spring Boot application.
Complete the code to enable auto-configuration in Spring Boot.
@[1] public class MyApp {}
The @SpringBootApplication annotation includes auto-configuration, component scanning, and configuration.
Fix the error in the Spring Boot application properties file to set server port to 8081.
server.[1]=8081
The property server.port sets the port number for the Spring Boot embedded server.
Fill both blanks to create a REST controller with a GET mapping in Spring Boot.
import org.springframework.web.bind.annotation.[1]; import org.springframework.web.bind.annotation.[2]; @[1] public class HelloController { @[2]("/hello") public String sayHello() { return "Hello, Spring Boot!"; } }
@RestController marks the class as a REST controller, and @GetMapping maps HTTP GET requests to the method.
Fill all three blanks to define a Spring Boot application with a component scan and enable configuration properties.
import org.springframework.context.annotation.[1]; import org.springframework.context.annotation.Configuration; import org.springframework.boot.context.properties.[2]; @[3] @[1]( scanBasePackages = {"com.example.app"} ) @[2] public class AppConfig {}
@ComponentScan tells Spring where to look for components, @EnableConfigurationProperties enables support for configuration properties, and @Configuration marks the class as a source of bean definitions.