22
22
import org .springframework .beans .BeansException ;
23
23
import org .springframework .beans .factory .InitializingBean ;
24
24
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
25
- import org .springframework .boot .web .context .ConfigurableWebServerApplicationContext ;
26
25
import org .springframework .boot .web .server .WebServer ;
27
26
import org .springframework .boot .web .server .WebServerException ;
28
27
import org .springframework .boot .web .servlet .ServletContextInitializer ;
@@ -53,7 +52,7 @@ public ServletWebServerFactory servletWebServerFactory() {
53
52
public static class ServerlessServletWebServerFactory
54
53
implements ServletWebServerFactory , ApplicationContextAware , InitializingBean {
55
54
56
- private ConfigurableWebServerApplicationContext applicationContext ;
55
+ private ApplicationContext applicationContext ;
57
56
58
57
@ Override
59
58
public WebServer getWebServer (ServletContextInitializer ... initializers ) {
@@ -77,28 +76,31 @@ public int getPort() {
77
76
78
77
@ Override
79
78
public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
80
- this .applicationContext = ( ConfigurableWebServerApplicationContext ) applicationContext ;
79
+ this .applicationContext = applicationContext ;
81
80
}
82
81
83
82
@ Override
84
83
public void afterPropertiesSet () throws Exception {
85
- if (applicationContext instanceof ServletWebServerApplicationContext servletApplicationContet ) {
84
+ if (applicationContext instanceof ServletWebServerApplicationContext servletApplicationContext ) {
86
85
logger .info ("Configuring Serverless Web Container" );
87
86
ServerlessServletContext servletContext = new ServerlessServletContext ();
88
- servletApplicationContet .setServletContext (servletContext );
87
+ servletApplicationContext .setServletContext (servletContext );
89
88
DispatcherServlet dispatcher = applicationContext .getBean (DispatcherServlet .class );
90
89
try {
91
90
logger .info ("Initializing DispatcherServlet" );
92
- dispatcher .init (new ProxyServletConfig (servletApplicationContet .getServletContext ()));
93
- logger .info ("Initalized DispatcherServlet" );
91
+ dispatcher .init (new ProxyServletConfig (servletApplicationContext .getServletContext ()));
92
+ logger .info ("Initialized DispatcherServlet" );
94
93
}
95
94
catch (Exception e ) {
96
- throw new IllegalStateException ("Faild to create Spring MVC DispatcherServlet proxy" , e );
95
+ throw new IllegalStateException ("Failed to create Spring MVC DispatcherServlet proxy" , e );
97
96
}
98
97
for (ServletContextInitializer initializer : new ServletContextInitializerBeans (this .applicationContext )) {
99
98
initializer .onStartup (servletContext );
100
99
}
101
100
}
101
+ else {
102
+ logger .debug ("Skipping Serverless configuration for " + this .applicationContext );
103
+ }
102
104
}
103
105
}
104
106
}
0 commit comments