API / Apache FreeMarker Interview questions
Explain how FreeMarker integrates with Spring MVC?
Spring provides first-class FreeMarker support through spring-context-support: a FreeMarkerConfigurer bean wraps and configures a freemarker.template.Configuration (setting templateLoaderPath, typically classpath:/templates/), and a FreeMarkerViewResolver maps view names returned by controllers to .ftl files.
@Bean public FreeMarkerConfigurer freemarkerConfig() { FreeMarkerConfigurer cfg = new FreeMarkerConfigurer(); cfg.setTemplateLoaderPath("classpath:/templates/"); return cfg; }
When a controller returns a view name, DispatcherServlet resolves it to a FreeMarkerView, which merges the Spring Model attributes directly into the FreeMarker data model and streams the result to the HttpServletResponse. Spring also ships a spring.ftl macro library with helpers for form binding, validation error display, and URL building, so templates can use idiomatic Spring form macros rather than hand-rolling them.
spring-boot-starter-freemarker auto-configures all of this out of the box. Spring's own documentation has increasingly pointed newer projects toward Thymeleaf as the more commonly recommended default, but the FreeMarker integration remains actively supported for teams that prefer it.
More Related questions...