0
0
Spring Bootframework~10 mins

Database and app orchestration in Spring Boot - Interactive Code Practice

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

Complete the code to define a Spring Boot application entry point.

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
Blaunch
Crun
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'launch' instead of 'run' causes errors.
Forgetting to pass the application class and args.
2fill in blank
medium

Complete the code to inject a JPA repository into a service class.

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

@Service
public class UserService {

    private final UserRepository userRepository;

    @Autowired
    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    // service methods
}
Drag options to blanks, or click blank then click option'
AAutowired
BInject
CResource
DQualifier
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Inject' without proper imports.
Confusing 'Qualifier' with injection annotation.
3fill in blank
hard

Fix the error in the repository interface declaration.

Spring Boot
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<[1], Long> {
}
Drag options to blanks, or click blank then click option'
AUserDTO
BUserEntity
CUserController
DUserService
Attempts:
3 left
💡 Hint
Common Mistakes
Using service or controller classes instead of entity.
Using DTO classes which are not entities.
4fill in blank
hard

Fill both blanks to create a REST controller method that fetches a user by ID.

Spring Boot
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/[1]")
    public UserEntity getUserById(@PathVariable [2] id) {
        return userService.findById(id);
    }
}
Drag options to blanks, or click blank then click option'
Aid
BuserId
CLong
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching path variable name and parameter name.
Using wrong data type like String for ID.
5fill in blank
hard

Fill all three blanks to define a Spring Data JPA query method that finds users by their email.

Spring Boot
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;

public interface UserRepository extends JpaRepository<UserEntity, Long> {
    Optional<UserEntity> findBy[1]([2] [3]);
}
Drag options to blanks, or click blank then click option'
AEmail
BString
Cemail
DId
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method name like findById instead of findByEmail.
Using wrong parameter type or name.