0
0
Spring Bootframework~10 mins

What is Spring Boot in Spring Boot - Interactive Quiz & Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a basic Spring Boot application class.

Spring Boot
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);
    }
}
Drag options to blanks, or click blank then click option'
Astart
Brun
Claunch
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'launch' instead of 'run' causes errors.
Forgetting to call a method to start the app.
2fill in blank
medium

Complete the annotation to mark the main class as a Spring Boot application.

Spring Boot
import org.springframework.boot.autoconfigure.SpringBootApplication;

@[1]
public class MyApp {}
Drag options to blanks, or click blank then click option'
ASpringBootApp
BComponentScan
CEnableAutoConfiguration
DSpringBootApplication
Attempts:
3 left
💡 Hint
Common Mistakes
Using only @EnableAutoConfiguration misses component scanning.
Using wrong annotation names causes the app not to start.
3fill in blank
hard

Fix the error in the code to correctly inject a service in Spring Boot.

Spring Boot
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.[1];

@Service
public class MyService {
    // service methods
}
Drag options to blanks, or click blank then click option'
AComponent
BInject
CAutowired
DResource
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Inject requires extra setup and is not default in Spring Boot.
Using @Component on a field is incorrect.
4fill in blank
hard

Fill both blanks to create a REST controller with a GET endpoint in Spring Boot.

Spring Boot
import org.springframework.web.bind.annotation.[1];
import org.springframework.web.bind.annotation.[2];

@[1]("/hello")
public class HelloController {
    @[2]("/")
    public String greet() {
        return "Hello, Spring Boot!";
    }
}
Drag options to blanks, or click blank then click option'
ARestController
BGetMapping
CController
DPostMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Controller instead of @RestController requires extra setup.
Using @PostMapping instead of @GetMapping changes the HTTP method.
5fill in blank
hard

Fill all three blanks to define a Spring Boot application with a service and controller.

Spring Boot
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

@SpringBootApplication
public class [1] {
    public static void main(String[] args) {
        SpringApplication.[2]([3].class, args);
    }
}

@Service
class GreetingService {
    public String greet() {
        return "Hello from service!";
    }
}

@RestController
class GreetingController {
    private final GreetingService service;

    @Autowired
    public GreetingController(GreetingService service) {
        this.service = service;
    }

    @GetMapping("/greet")
    public String greet() {
        return service.greet();
    }
}
Drag options to blanks, or click blank then click option'
AApplication
Brun
CMyApp
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using different class names in main and run causes errors.
Using 'start' instead of 'run' causes runtime errors.