Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServletConfigAware-related exception is not thrown as expected [SPR-9855] #14488

spring-projects-issues opened this issue Oct 4, 2012 · 3 comments
in: web type: bug type: documentation


Copy link

@spring-projects-issues spring-projects-issues commented Oct 4, 2012

Ivan Sopov opened SPR-9855 and commented

From the ServletConfigAware javadoc:

Only satisfied if actually running within a Servlet-specific
WebApplicationContext. If this callback interface is encountered
elsewhere, an exception will be thrown on bean creation

But I have not been able to reproduce exception throwing and I have not found it in the source. E.g. this code illustrates that ServletConfigAware interface does not work and exception is not thrown:

package com.sopovs.moradanen;

import javax.servlet.ServletConfig;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletConfigAware;

public class ServletConfigAwareTest {

	public static void main(String[] args) {
		System.out.println(new AnnotationConfigApplicationContext(

		AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
		webContext.setServletConfig(new MockServletConfig());

		// where is my exception?

	public static class Foo implements ServletConfigAware {

		public void setServletConfig(ServletConfig servletConfig) {



Affects: 3.1.2

Referenced from: commits 7fdb637, 03c3dc3

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 24, 2012

Chris Beams commented

Ivan Sopov, thanks for the report. I've done a quick verification based on your sample that indeed an exception is not thrown when you might expect it to be based on the Javadoc for ServletConfigAware. At this point, the correct solution may be to update the documentation, as there may be existing applications that depend on the fact that no exception is thrown, whether intentionally or by accident. i.e. it could be a backward compatibility issue to begin throwing such an exception now.

philwebb, I've scheduled this for the General Backlog, but feel free to pick it up if you'd like to take a little deeper look and determine whether a doc fix is indeed appropriate.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 24, 2012

Ivan Sopov commented

Yes, I think removing this statement from javadoc is perfectly fine. However warning or error in logs may be useful in such case.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 31, 2012

Juergen Hoeller commented

Indeed, I'm simply removing that statement from the documentation there, making clear that no ServletConfig will be set when not running within a Servlet-specific WebApplicationContext. This is the intended behavior, actually, since we're using ServletConfigAware ourselves to check for the optional introspection of Servlet-specific init parameters...


@spring-projects-issues spring-projects-issues added type: bug type: documentation in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.1.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: web type: bug type: documentation
None yet

No branches or pull requests

2 participants