1

I have a Java Spring MVC based web app.

I have three different @Controller classes with a variety of @RequestMapping methods that handle all web requests to the application.

Works great.

Now I have implemented a licensing system so there must be a license file in place for the application to be used.

When any web request is made, I will check the license file to make sure it is not expired and show a "License is expired, contact support" message.

My question is ...

Is there a way to hook into every call made through the Spring MVC dispatch servlet or every @Controller method so I can check licensing in one place?

I could so something like put a licenseService.checkLicense() in every @Controller method, but I'd rather do it in one place because it would be cleaner.

AndySummers2020
  • 411
  • 1
  • 6
  • 14
  • 1
    In Spring lingo, they call it an interceptor :) – blurfus Jun 30 '20 at 18:01
  • 1
    @blurfus Thanks for the help, I'll give it a try and report back. – AndySummers2020 Jun 30 '20 at 22:02
  • @blurfus Turns out that I need slightly different "License check" logic in various specific places, so one "interceptor" probably wasn't the best approach for me. But I think your answer was correct. – AndySummers2020 Jul 03 '20 at 03:31
  • if you structure it correctly, you could use an interceptor to call a class that does the check and then re-use this class/check from the other specific places you are mentioning – blurfus Jul 03 '20 at 03:33
  • @blurfus ... thanks for the suggestion. I'd rather it was all handled in one place, so I will likely revisit this area of the product once I get 1.0 out the door. – AndySummers2020 Jul 03 '20 at 03:44
  • 1
    it would be handled in one place but called from two different points as needed. Good luck with your product :) – blurfus Jul 03 '20 at 05:44

0 Answers0