Issue Details (XML | Word | Printable)

Key: SPR-4008
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Sam Brannen
Reporter: Bertrand Fovez
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

Supply an opportunity to customize context before calling refresh in ContextLoaders (web.context and test.context)

Created: 26/Oct/07 06:20 AM   Updated: 08/Nov/07 09:35 AM   Resolved: 07/Nov/07 03:34 PM
Component/s: SpringCORE
Affects Version/s: None
Fix Version/s: 2.5 RC2

Time Tracking:
Not Specified


 Description  « Hide

First of all, congratulations for this huge and tremendous job!

For some reason, we need to dynamically add BeanFactoryPostProcessors (PropertyPlaceholderConfigurers here) to a a context AFTER config locattions have been assigned but BEFORE context.refresh() call.

In order to achieve this, we overrode web.context.ContextLoader.createWebApplicationContext(). Another way would probably have had to set an ad-hoc parent context.

Starting with 2.5, we were to proceed the same way with test.context.ContextLoader. Unfortunately, test.context.AbstractGenericContextLoader.loadContext() is final.

The idea is to supply an abstract customizeContext() method (just like the supplied customizeBeanFactory() method) in both web.context.ContextLoader and test.context.ContextLoader.

Thank you for your feedback.



Sam Brannen added a comment - 03/Nov/07 08:56 AM

Hi Bertrand,

> First of all, congratulations for this huge and tremendous job!

Thanks!

> The idea is to supply an abstract customizeContext() method (just like the
> supplied customizeBeanFactory() method) in both web.context.ContextLoader and
> test.context.ContextLoader.

That's a good idea, and I've implemented it using empty implementations instead of
abstract methods as follows.

ContextLoaders now provide an opportunity for subclasses to customize the context
before calling refresh. For details see:

  • org.springframework.web.context.ContextLoader.customizeContext(ConfigurableWebApplicationContext)
  • org.springframework.test.context.support.AbstractGenericContextLoader.customizeContext(GenericApplicationContext)

Feel free to try it out in one of the upcoming nightly snapshots for Spring 2.5 RC2.

Regards,

Sam


Bertrand Fovez added a comment - 06/Nov/07 03:16 AM

Thanks Sam.

For now, the fix doesn't seem to appear in the current nightly snapshot (#20071105-291).

Regards,

Bertrand


Sam Brannen added a comment - 06/Nov/07 05:32 AM

Hi Bertrand,

The new ContextLoader code is in CVS, but you are correct: it doesn't show up in the
nightly snapshots. Thus, I've created a new issue (SPR-4048) to address this issue.

Thanks for pointing this out!

Sam


Bertrand Fovez added a comment - 07/Nov/07 04:28 AM

Hi Sam,

We could find the fix out in the latest nighty build. Thanks.

We face two issues:

  • For AbstractGenericContextLoader.customizeContext, the fix seems to be perfect, but we couldn't achieve testing it because we could'nt subclass TestContext for some reasons I explained in this new issue: SPR-4056.
  • For ContextLoader.customizeContext, it's my fault: I should have been more accurate in my previous report. In fact, in order to customize context, we need to grab information which is accessible through the servletContext. Therefore, we need this signature or equivalent: ContextLoader.customizeContext(final ConfigurableWebApplicationContext, final ServletContext). Maybe we could capture servletContext overriding ContextLoader.createWebApplicationContext and storing it in an instance variable, but ContextLoader is not meant to be stateful, right?

Sorry for that.

Bertrand


Sam Brannen added a comment - 07/Nov/07 07:00 AM

Reopened to address Bertrand's latest comments regarding the ServletContext in the web ContextLoader.


Sam Brannen added a comment - 07/Nov/07 03:34 PM

org.springframework.web.context.ContextLoader's customizeContext() method
now has the following signature:

customizeContext(ServletContext,ConfigurableWebApplicationContext)

cheers,

Sam


Bertrand Fovez added a comment - 08/Nov/07 09:35 AM

Thanks Sam.

Furthermore, I'm glad to tell you that I could get through SPR-4056 issue thank to your comment. My goal was not to deal with context locations, but I used modifyLocations() and generateDefaultLocations() as hooks supplying actual test class to do the job.

I owe you one!

Bertrand