Spring Boot In Action | AUTHENTIC ⟶ |

@SpringBootTest @AutoConfigureMockMvc class BookControllerTest @Autowired private MockMvc mockMvc;

public interface BookRepository extends JpaRepository<Book, Long> List<Book> findByAuthor(String author); Spring Boot In Action

@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&lt

@Service @RequiredArgsConstructor public class BookService private final BookRepository bookRepo; public Book saveBook(Book book) return bookRepo.save(book); \"author\":\"Craig Walls\"")) .andExpect(status().isOk())

./mvnw package

./mvnw spring-boot:run → Open http://localhost:8080/api/hello application.properties (or YAML) # Server server.port=9090 server.servlet.context-path=/myapp Logging logging.level.org.springframework=INFO Data source (real DB later) spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=secret