-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bugtype: documentationA documentation taskA documentation task
Milestone
Description
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;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
@Configuration
public class ServletConfigAwareTest {
public static void main(String[] args) {
System.out.println(new AnnotationConfigApplicationContext(
"com.sopovs.moradanen").getBean(Foo.class).hashCode());
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.scan("com.sopovs.moradanen");
webContext.setServletConfig(new MockServletConfig());
webContext.afterPropertiesSet();
System.out.println(webContext.getBean(Foo.class).hashCode());
// where is my exception?
}
@Component
public static class Foo implements ServletConfigAware {
public void setServletConfig(ServletConfig servletConfig) {
System.out.println("Bingo!");
}
}
}
Affects: 3.1.2
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bugtype: documentationA documentation taskA documentation task