In our web-app we have both @Controller classes and @RestController.
How would you suggest to organize them in our internal project structure project (packages/module) and url mapping wise?
In our web-app we have both @Controller classes and @RestController.
How would you suggest to organize them in our internal project structure project (packages/module) and url mapping wise?
Concerning Package structure you have two options. layer vs component packaging.
Layer packaging preserves policy that layer beans are in same packages (e.g. UserController
, InvoiceController
are in
com.example.application.web
package and UserService
,
InvoiceService
are in com.example.application.service
package).
This is most common in the wild.
Component packaging preserves policy package per feature (e.g. UserController
, UserService
are in
com.example.application.user
and InvoiceController
,
InvoiceService
are in com.example.application.invoice
).
I had experience only with Layer packaging so far and gained opinion that Component packaging would solve a lot of problems (especially coupling problems as you can often use package private beans instead of public). So if it would be up to me, I would go with latter approach.
But your team has to decide which structure to use and stick with it.
You can read more about pros and cons in this SO thread