4
4
import org .springframework .boot .SpringApplication ;
5
5
import org .springframework .boot .autoconfigure .SpringBootApplication ;
6
6
import org .springframework .boot .web .support .SpringBootServletInitializer ;
7
+ import org .springframework .context .annotation .Bean ;
7
8
import org .springframework .context .annotation .ComponentScan ;
9
+ import org .springframework .web .servlet .HandlerAdapter ;
10
+ import org .springframework .web .servlet .HandlerExceptionResolver ;
11
+ import org .springframework .web .servlet .HandlerMapping ;
12
+ import org .springframework .web .servlet .ModelAndView ;
13
+ import org .springframework .web .servlet .mvc .method .annotation .RequestMappingHandlerAdapter ;
14
+ import org .springframework .web .servlet .mvc .method .annotation .RequestMappingHandlerMapping ;
15
+
16
+ import javax .servlet .http .HttpServletRequest ;
17
+ import javax .servlet .http .HttpServletResponse ;
8
18
9
19
10
20
@ SpringBootApplication
@@ -15,6 +25,40 @@ public class Application extends SpringBootServletInitializer {
15
25
@ Value ("${logging.level.root:OFF}" )
16
26
String message = "" ;
17
27
28
+ /*
29
+ * Create required HandlerMapping, to avoid several default HandlerMapping instances being created
30
+ */
31
+ @ Bean
32
+ public HandlerMapping handlerMapping () {
33
+ return new RequestMappingHandlerMapping ();
34
+ }
35
+
36
+ /*
37
+ * Create required HandlerAdapter, to avoid several default HandlerAdapter instances being created
38
+ */
39
+ @ Bean
40
+ public HandlerAdapter handlerAdapter () {
41
+ return new RequestMappingHandlerAdapter ();
42
+ }
43
+
44
+ /*
45
+ * optimization - avoids creating default exception resolvers; not required as the serverless container handles
46
+ * all exceptions
47
+ *
48
+ * By default, an ExceptionHandlerExceptionResolver is created which creates many dependent object, including
49
+ * an expensive ObjectMapper instance.
50
+ */
51
+ @ Bean
52
+ public HandlerExceptionResolver handlerExceptionResolver () {
53
+ return new HandlerExceptionResolver () {
54
+
55
+ @ Override
56
+ public ModelAndView resolveException (HttpServletRequest request , HttpServletResponse response , Object handler , Exception ex ) {
57
+ return null ;
58
+ }
59
+ };
60
+ }
61
+
18
62
public static void main (String [] args ) {
19
63
SpringApplication .run (Application .class , args );
20
64
}
0 commit comments