Assignment 05
Design and deploy Bus Reservation System using Spring
Web
Step 1: Create Project Using Spring Initializr
Go to [Link]
Choose:
Project: Maven
Language: Java
Spring Boot Version: Latest stable
Group: [Link]
Artifact: bussystem
Name: BusManagementSystem
Packaging: Jar
Java: 17 or above
Dependencies:
Spring Web
Spring Data JPA
MySQL Driver
Spring Boot DevTools (optional for hot reload)
93 1
Click on Generate → Extract the ZIP file.
Step 2: Import the Project
Open IDE → File → Import → Maven → Existing Maven Projects → Select
extracted folder → Finish
Step 3: Configure [Link] dependencies (already included if you used Spring
Initializr)
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
93 2
<dependency>
<groupId>[Link]</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
Step 4: Create Model (Entity) Class — [Link]
@Entity
public class Book {
@Id
@GeneratedValue(strategy = [Link])
private Long id;
private String title;
private String author;
private String isbn;
93 3
private int quantity;
// Getters & Setters
Step 5: Create Repository — [Link]
@Repository
public interface BookRepository extends JpaRepository<Book, Long> {
Step 6: Create Service Layer — [Link]
@Service
public class BookService {
@Autowired
private BookRepository bookRepo;
public List<Book> getAllBooks()
{ return [Link]();
public Book addBook(Book book) {
93 4
return [Link](book);
public void deleteBook(Long id) {
[Link](id);
Step 7: Create Controller — [Link]
@RestController
@RequestMapping("/books")
public class BookController {
@Autowired
private BookService bookService;
@GetMapping
public List<Book> getBooks()
{ return
[Link]();
93 5
@PostMapping
public Book addBook(@RequestBody Book book)
{ return [Link](book);
@DeleteMapping("/{id}")
public void deleteBook(@PathVariable Long id) {
[Link](id);
Step 8: Configure MySQL Connection
Add to [Link]
[Link]=jdbc:mysql://localhost:3306/busdb
[Link]=root
[Link]=your_password
[Link]-auto=update
[Link]-sql=true
Create a database busdb in MySQL before running.
93 6
Step 9: Run the Application
Right click on [Link] → Run as Java
Application
TEST CASES:
Test
Case ID Test Scenario Input Expected Output Result
TC01 Returns list of all books
Get all books GET /books
(JSON) Pass/Fail
POST /books with Returns saved book with
TC02 Add new book JSON {title, author...} Pass/Fail
generated id
Delete existing Deletes book with ID 1 and
TC03 book DELETE /books/1 Pass/Fail
returns no content
Get books when GET /books (empty
TC04 none exist Returns empty list [] Pass/Fail
DB)
Add book with POST /books with Returns error (400 Bad
TC05 missing data Pass/Fail
missing title Request or validation
msg)
93 7