Mage Mage - 4 years ago 288
Groovy Question

Spring Boot and context path

I've done a sample web application recently using spring boot and groovy templates. I didn't find a simple way to provide my templates with servlet context path to get static resources urls right. Is there a way to do it? A more general way than inject request or servletcontext into controller methods? One thing i can think of is custom model attribute, but i think it's a hack rather than good solution to the problem.

Answer Source

In groovy templates a RequestContext object is available as a parameter with name 'spring'. So all I had to do in view is

spring.getContextUrl('/link/to/some/resource')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download