Spring Boot In Action May 2026
public interface BookRepository extends JpaRepository<Book, Long> List<Book> findByAuthor(String author);
Add dependency:
@SpringBootTest @AutoConfigureMockMvc class BookControllerTest @Autowired private MockMvc mockMvc; Spring Boot In Action
./mvnw package
@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()); public interface BookRepository extends JpaRepository<
@Service @RequiredArgsConstructor public class BookService private final BookRepository bookRepo; public Book saveBook(Book book) return bookRepo.save(book);
@Entity @Data @NoArgsConstructor public class Book @Id @GeneratedValue private Long id; private String title; private String author; \"author\":\"Craig Walls\"")) .andExpect(status().isOk())
java -jar target/myapp-0.0.1-SNAPSHOT.jar