We don't want to add all of our API routes (that is what these lambda expressions are called in Jooby) to the
Server class (since we will end up with quite a few before we are finished). We should create a student module that defines the web service API for managing student domain data. This also allows us to easily turn the student module into its own microservice since we can create a server class that only loads this module.
Create a new class in the
web package named
StudentModule. Make it extend
Add a default constructor.
Move the two routes from the server constructor into the constructor of the new class. You should remove the original versions of the routes from the
setServerOptions call and DAO field where they.
DAO injection time. Modify the constructor in the new class so that it takes the DAO as a parameter. Remember to use the interface type.
The server class will create the DAOs and pass them into the modules.
Back in the server class add the following to the constructor:
mount method will add all of the routes that were declared in the
StudentModule to the service.
Restart and test that the server still works correctly.