Skip to content

Ordering of ServletContextAware and ApplicationContextAware callbacks makes testing FreeMarkerView (and similar classes) impossible [SPR-5398] #10071

Closed

Description

@spring-projects-issues

Dave Syer opened SPR-5398 and commented

Ordering of ServletContextAware and ApplicationContextAware callbacks makes testing servlet aware components impossible. I want to test a configuration that contains a FreeMarkerView (which is ServletContextAware), so I added a ServletContextAwareProcessor to my test config, with a MockServletContext. Unfortunately this doesn't work because FreeMarkerView has a base class which is ApplicationContextAware, and it assumes that either the ServletContext is already set or the ApplicationContext is an instance of WebApplicationContext, and neither is the case. But the ServletContext is available, and will eventually be set, so the initialisation is just happening too eagerly. Is it possible to put it in a more orthodox place (like afterPropertiesSet())?


Affects: 2.5.6, 3.0 M1

Activity

  1. spring-projects-issues commented on Mar 25, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've addressed this for FreeMarkerView and also for ResourceBundleViewResolver and XmlViewResolver, all of which initialized in the initApplicationContext callback while actually being dependent on the ServletContext as well... They are simply performing that initialization in afterPropertiesSet now, as you suggested.

    Juergen

  2. spring-projects-issues commented on Mar 25, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Actually, FreeMarkerView performs it in an initServletContext callback now, since its initialization is very much based on the ServletContext. The original problem should nevertheless disappear.

  3. added
    type: enhancement
    in: core
    on Jan 11, 2019
  4. added this to the 3.0 M3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions