Open v79 opened 5 years ago
Yes, this is expected. Every time you call before {}
you create an independent filter which executes on all paths.
I can kinda see why. I'll have a rethink about my design, unless you're planning on adding a beforeBefore{} method which only runs once :). Thanks for confirming.
Using spark-kotlin, but I imagine the same is true of sparkjava:
I've declared several "Controller" classes, each with their own routes defined (
HomeController
for "/",PageController
for "/pages", etc). These controllers all inherit from anAbstractController
class. TheAbstractController
class defines thebefore
route for authentication, logging, etc.I now have 5 such controllers. And it seems the
before
route is evaluated 5 times for every request.Then logging for every request shows:
qtp1205109442-17] INFO org.liamjd.bascule.controllers.AbstractController - - before AbstractController - 2018-08-22T20:17:10.229Z [qtp1205109442-17] INFO org.liamjd.bascule.controllers.AbstractController - - before AbstractController - 2018-08-22T20:17:10.229Z [qtp1205109442-17] INFO org.liamjd.bascule.controllers.AbstractController - - before AbstractController - 2018-08-22T20:17:10.229Z [qtp1205109442-17] INFO org.liamjd.bascule.controllers.AbstractController - - before AbstractController - 2018-08-22T20:17:10.230Z [qtp1205109442-17] INFO org.liamjd.bascule.controllers.AbstractController - - before AbstractController - 2018-08-22T20:17:10.230Z
Is this expected behaviour? Should the
before
route be evaluated 5 times, once per Controller? Maybe I'm trying to force an MVC approach onto Spark where it doesn't really fit...