Complete the code to define a Spring Boot application with an embedded server.
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 with the embedded server.
Complete the code to specify the embedded server port in application.properties.
server.[1]=8081
The property server.port sets the port number for the embedded server in Spring Boot.
Fix the error in the code to create a REST controller with embedded server.
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") public String [1]() { return "Hello, World!"; } }
The method name can be any valid Java method name. getHello is a clear name for a GET endpoint.
Fill both blanks to configure the embedded Tomcat server's max threads and port in application.properties.
server.[1]=9090 server.tomcat.threads.[2]=200
server.port sets the port number, and server.tomcat.threads.max sets the maximum threads for the embedded Tomcat server.
Fill all three blanks to create a Spring Boot application class with embedded server and a REST endpoint.
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class [1] { public static void main(String[] args) { SpringApplication.[2]([3].class, args); } @GetMapping("/greet") public String greet() { return "Greetings from embedded server!"; } }
The class name MyApplication is used consistently. The SpringApplication.run() method starts the embedded server.