Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable caching in a Spring Boot application.
Spring Boot
@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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'launch' instead of 'run' causes errors.
Forgetting to call any method to start the app.
✗ Incorrect
The SpringApplication.run() method starts the Spring Boot application.
2fill in blank
mediumComplete the annotation to enable caching support in Spring Boot.
Spring Boot
@Configuration [1] public class CacheConfig { }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @EnableScheduling or other unrelated annotations.
Forgetting to add any caching annotation.
✗ Incorrect
The @EnableCaching annotation activates Spring's annotation-driven cache management capability.
3fill in blank
hardFix the error in the Redis cache manager bean definition.
Spring Boot
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory factory) {
return RedisCacheManager.[1](factory).build();
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' or 'Builder' causes compilation errors.
Using incorrect method names for builder pattern.
✗ Incorrect
RedisCacheManager.builder(factory) returns a builder to configure and build the cache manager.
4fill in blank
hardFill both blanks to configure a RedisTemplate bean with String keys and values.
Spring Boot
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> template = new RedisTemplate<>();
template.setConnectionFactory([1]);
template.setKeySerializer([2]);
return template;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong serializer for keys causes data issues.
Passing wrong variable name for connection factory.
✗ Incorrect
The RedisTemplate needs the RedisConnectionFactory to connect and a StringRedisSerializer to serialize keys as strings.
5fill in blank
hardFill both blanks to create a cacheable service method with Redis cache.
Spring Boot
public class UserService { @Cacheable(cacheNames = [1]) public User getUserById([2] id) { // fetch user from database return userRepository.findById(id); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cache name string or missing quotes.
Using wrong parameter type like int instead of Long.
✗ Incorrect
The @Cacheable annotation requires a cache name string like 'userCache'. The method parameter type for id is Long.