Spring Boot In Action 📌
@SpringBootTest @AutoConfigureMockMvc class BookControllerTest @Autowired private MockMvc mockMvc;
Add dependency:
@Entity @Data @NoArgsConstructor public class Book @Id @GeneratedValue private Long id; private String title; private String author; Spring Boot In Action
application-dev.properties , application-prod.properties Activate: spring.profiles.active=dev 5. Data Persistence (JPA + Repository) Entity: private String title
management.endpoints.web.exposure.include=health,info,metrics Build a fat JAR: private String author
@Service @RequiredArgsConstructor public class BookService private final BookRepository bookRepo; public Book saveBook(Book book) return bookRepo.save(book);
@Test void shouldCreateBook() throws Exception mockMvc.perform(post("/api/books") .contentType(MediaType.APPLICATION_JSON) .content("\"title\":\"Spring Boot in Action\",\"author\":\"Craig Walls\"")) .andExpect(status().isOk());