Enterprise Architectures - Lab 3
[valid 2026-2027]
Dependency Injection and Cross-Cutting Concerns
Compulsory (1p)
- Create a simple, illustrative scenario that demonstrates all major types of dependency injection points in Spring Boot.
- Your example must also prove the order in which injection is performed: constructor → field → setter & method.
Homework (2p)
Create a Library Management System that handles Members, Books, and Book Borrowing.
Different libraries using your system require different borrowing policies, such as:
- There is a fixed limit regarding how many books can be borrowed (default);
- The number of books that can be borrowed depends on the role of the member (student / regular / premium);
Design a pluggable borrowing mechanism where Spring selects the appropriate BorrowingPolicy implementation depending on the library configuration.
- Define the domain model and simple in-memory repositories for members and books.
- Create the implementations for the different borrowing policies.
- Use a custom configuration property to decide which borrowing policy to inject.
- Create the BorrowingService which processes book borrowing and validates them using the injected BorrowingPolicy.
- Use constructor-based dependency injection to wire the services and repositories.
- Every time a book is borrowed or returned, use an aspect to log the method name, member name, book title, and execution time.
- Create an aspect that, before a book is borrowed, checks if the member exists, the book is available, and the member has not exceeded the borrowing limit.
If any condition is violated, throw a custom exception.
- Use an aspect to intercept exceptions thrown during borrowing operations and log the error message and the operation that failed.
- Publish an event whenever a member borrows more than a certain number of books and implement a listener that handles this event.
Advanced (2p)
- Consider a scenario where borrowing policies involve complex business rules that may change frequently as new membership types or restrictions are introduced.
Use a rule engine, such as Drools, to separate business rules from the application logic,
making the system easier to maintain and extend.
- Implement the borrowing policies using the rule engine. The rules should determine whether a member is allowed to borrow a book,
based on factors such as membership type, number of currently borrowed books, book type and availability.
They should also determine the borrowing period.
Make it possible to add or modify borrowing rules without changing the BorrowingService implementation.