Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:25:48+00:00 2026-06-15T20:25:48+00:00

I have a Spring MVC web app which uses FreeMarker for rendering the views

  • 0

I have a Spring MVC web app which uses FreeMarker for rendering the views and have come up with the following issue.

Within my FreeMarker config I declare a Singleton Spring bean as a FreeMarker variable and within my application I have provided the mechanism for the Singleton Bean to be dynamically refreshed (the bean contains the application config retrieved from the DB).

Now the problem is that when it is refreshed the previously rendered FreeMarker templates use the values within the older version yet if I navigate to a page not rendered since the container started it uses the new values.

The following is a snippet of my FreeMarker config:

<!-- FreeMarker config -->

<bean id="freemarkerViewConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPaths">
        <array>
            <value>/WEB-INF/freemarker</value>
            <value>classpath:/WEB-INF/freemarker</value>
        </array>
    </property>
    <property name="freemarkerSettings">
        <props>
            <prop key="datetime_format">dd/MM/yyyy</prop>
            <prop key="number_format">#</prop>
            <prop key="whitespace_stripping">true</prop>
            <prop key="auto_import">
                spring.ftl as spring,
                custom-macros.ftl as custom,
            </prop>
        </props>
    </property>
    <property name="freemarkerVariables">
        <map>
            <entry key="xml_escape" value-ref="fmXmlEscape"/>
            <entry key="html_escape" value-ref="fmHtmlEscape"/>
            <entry key="config" value-ref="config"/>
        </map>
    </property>
</bean>

To refresh the config model I execute the following within my Controller class:

((XmlWebApplicationContext)applicationContext).refresh();

Having this configuration picks up the refreshed config model when accessing a page which hasn’t been already rendered but won’t recognise the change on pages already visited.

I have tried the following to enforce the ‘refresh’ of the variable with no luck:

  1. In the controller after the context is refresh I clear the templateCache within the FreeMarker Config which has been autowired:

    freeMarkerConfig.getConfiguration().clearTemplateCache();

  2. I have also tried disabling the caching of templates within the FreeMarker config using the following property within freeMarkerSettings:

    freemarker.cache.NullCacheStorage

Finally, its worth pointing out that when in debug and looking through the cache and configuration the Shared Variable does indeed reference the most up to date config model yet the page renders using the older version.

Any advice / guidance on how to resolve this?

ps I am using Spring v3.1.1.RELEASE and FreeMarker v2.3.19

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:25:50+00:00Added an answer on June 15, 2026 at 8:25 pm

    Not quite a solution but I have fixed my issue but it is more a hack to be honest.

    I changed the code to refresh my config by using the following command so only the config bean was recreated:

    ((DefaultListableBeanFactory) beanFactory).destroySingleton("config");
    

    And then modified the freemarker config by removing the reference to the config model as regardless what I tried I could not get this to be refreshed. So the solution to my issues was then to modify the BaseController which every controller within the application extends exposing the config model available as a @ModelAttribute so it was available to all the views.

    As I said doesn’t really solve the underlying issue but I have solved my problem albeit in a unorthodox fashion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring web app that uses Hibernate and Velocity. It's an MVC
I have configured in following way that spring MVC app using Spring 3.1.1.RELEASE web.xml
I have a Spring MVC application which uses FreeMarker as View technology (But maybe
I need to have theme support for a Spring MVC web app which includes
I have put together a simple ASP.NET MVC 3 test web app that uses
I have an ASP.NET MVC web app which includes the facility for clients to
We have a spring web app with spring mvc controllers. It's supposed to connect
I have to load 3 spring config xml files in myproj spring mvc app
We have a Spring MVC web app (WAR) deploying to Tomcat (6.0.35) that launches
I have a Spring Web MVC application that I'd like to serve a large,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.