I'm thinking about moving my older Spring MVC application to use the Java Template Engine (JTE), but I'm seeing that many pages rely on application scoped variables. Is there a way to access these variables in JTE without needing to pass them as parameters for every single endpoint?
3 Answers
For further support, check out the GitHub project for JTE. You might find some insights on how to expose request attributes there, especially for what you're referring to as scope variables. You can also implement a HandlerInterceptor for this. If you’re okay with some boilerplate, you can grab the request parameters/attributes directly using @ModelAttribute to fill a mutable model to pass to the JTE template.
Hey! Are you referring to a specific template engine like ThymeLeaf, Freemarker, or JSP? Knowing which one can help figure things out better.
I meant JTE specifically. Thanks for asking!
You could use a @ControllerAdvice with @ModelAttribute to centralize the injection of whatever you need into all your templates. It’s a clean way to handle it!

I’m specifically worried about application scoped variables, though—they seem tricky to manage since they're not set up for each endpoint.