Skip to content

MockServletContext hardcoded to return 2.5 for servlet version [SPR-6194] #10862

Closed
@spring-projects-issues

Description

@spring-projects-issues

Bob Jacoby opened SPR-6194 and commented

MockServletContext is hardcoded to return '5' for the servlet minor version.

org.springframework.web.context.ContextLoader contains a check of the servlet version number to determine whether or not to call a servlet 2.5 API method.

// Assign the best possible id value.
if (servletContext.getMajorVersion() > 2 || servletContext.getMinorVersion() >= 5) {
     // Servlet 2.5's getContextPath available!
     wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContext.getContextPath());
}

Since MockServletContext will return 2.5 as the servlet version, our 2.4 servlet api test code throws a runtime exception when the ContextLoader attempt to call the 2.5 API method.

Could setters be provided for the major/minor version numbers in MockServletContext? The 2.5 method getContextPath could also throw an exception if called when the mock context is set to 2.4.

I consider this a bug as I thought it was supposed to be able to be used in a 2.4 environment. If not, I guess this is a enhancement/improvement. :)


Affects: 3.0 RC1

Referenced from: commits 9a111e5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions