Spring Boot In Action [hot] [TOP — STRATEGY]
@Test void shouldCreateUser() throws Exception { User user = new User("test@example.com"); given(userService.save(any())).willReturn(user); mockMvc.perform(post("/api/users") .contentType(MediaType.APPLICATION_JSON) .content("{\"email\":\"test@example.com\"}")) .andExpect(status().isCreated()) .andExpect(jsonPath("$.email").value("test@example.com")); }
@Service public class UserService { @Cacheable(value = "users", key = "#id") public User findById(Long id) { return userRepository.findById(id).orElseThrow(); } spring boot in action
@Scheduled(cron = "0 0 * * * *") public void hourlyTask() { // Runs every hour } @Test void shouldCreateUser() throws Exception { User user
myapp: custom-property: value @ConfigurationProperties(prefix = "myapp") @Component public class AppProperties { private String customProperty; private EmailConfig email = new EmailConfig(); // getters/setters @Data public static class EmailConfig { private String host; private int port; } } private EmailConfig email = new EmailConfig()