-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAppInitializer.java
91 lines (81 loc) · 3.65 KB
/
AppInitializer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package net.liuxuan.spring.mvc;
import org.apache.catalina.security.SecurityConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
import javax.servlet.ServletRegistration;
/**
* Copyright (c) 2010-2016. by Liuxuan All rights reserved.
* ***************************************************************************
* 源文件名: net.liuxuan.spring.mvc.AppInitializer
* 功能:
* 版本: @version 1.0
* 编制日期: 2016/2/27 14:25
* 修改历史: (主要历史变动原因及说明)
* YYYY-MM-DD | Author | Change Description
* 2016/2/27 | Moses | Created
*/
//@Order(2)
@Controller
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
private static Logger log = LoggerFactory.getLogger(AppInitializer.class);
/**
* Specify {@link Configuration @Configuration}
* and/or {@link Component @Component} classes to be
* provided to the {@linkplain #createRootApplicationContext() root application context}.
*
* @return the configuration classes for the root application context, or {@code null}
* if creation and registration of a root context is not desired
*/
@Override
protected Class<?>[] getRootConfigClasses() {
log.debug("=====================***********1*************===================");
// return new Class[] {ServicesConfig.class, PersistenceConfig.class, SecurityConfig.class};
return null;
}
/**
* Specify {@link Configuration @Configuration}
* and/or {@link Component @Component} classes to be
* provided to the {@linkplain #createServletApplicationContext() dispatcher servlet
* application context}.
*
* @return the configuration classes for the dispatcher servlet application context or
* {@code null} if all configuration is specified through root config classes.
*/
@Override
protected Class<?>[] getServletConfigClasses() {
log.debug("=====================************2************===================");
// return new Class<?>[0];
return null;
}
/**
* Specify the servlet mapping(s) for the {@code DispatcherServlet} —
* for example {@code "/"}, {@code "/app"}, etc.
*
* @see #registerDispatcherServlet(ServletContext)
*/
@Override
protected String[] getServletMappings() {
log.debug("=====================***********3*************===================");
return new String[]{"/"};
}
@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
log.debug("=====================*************4***********===================");
registration.setInitParameter("throwExceptionIfNoHandlerFound", "true");
}
@Override
protected DispatcherServlet createDispatcherServlet(WebApplicationContext servletAppContext) {
final DispatcherServlet dispatcherServlet = (DispatcherServlet) super.createDispatcherServlet(servletAppContext);
log.debug("=====================*************5***********===================");
dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
return dispatcherServlet;
}
}