古人学问无遗力,少壮工夫老始成。这篇文章主要讲述WebAppInitializer类,代替web.xml相关的知识,希望能为你提供帮助。
1 package com.ssm.yjblogs.config; 2 3 import javax.servlet.MultipartConfigElement; 4 import javax.servlet.ServletRegistration.Dynamic; 5 6 import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 7 8 //使用注解配置方式初始化P386页 9 public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 10 11// Spring IoC环境配置 12@Override 13protected Class< ?> [] getRootConfigClasses() { 14// 配置Spring IoC资源 15return new Class< ?> [] { RootConfig.class }; //获取Spring Ioc容器的java配置类,用以装载各类Spring Bean 16} 17 18// DispatcherServlet环境配置 19@Override 20protected Class< ?> [] getServletConfigClasses() { 21// 加载Java配置类 22return new Class< ?> [] { WebConfig.class }; //获取各类Spring MVC的URI和控制器的配置关系类 23} 24 25// DispatchServlet拦截请求配置 26@Override 27protected String[] getServletMappings() { 28return new String[] { "*.do" }; //定义DispatcherServlet拦截的请求 29} 30 31/** 32* @param dynamic 33*Servlet上传文件配置. 34*/ 35@Override 36protected void customizeRegistration(Dynamic dynamic) {//P443页 37// 配置上传文件路径 38String filepath = "e:/mvc/uploads"; 39// 限制请求单个文件5MB 40Long singleMax = (long) (5 * Math.pow(2, 20)); 41// 总文件10MB 42Long totalMax = (long) (10 * Math.pow(2, 20)); 43// 设置上传文件配置 44dynamic.setMultipartConfig(new MultipartConfigElement(filepath, singleMax, totalMax, 0)); 45} 46 47 }
【WebAppInitializer类,代替web.xml】 无行号版本:
package com.ssm.yjblogs.config; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletRegistration.Dynamic; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; //使用注解配置方式初始化P386页 public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {// Spring IoC环境配置 @Override protected Class< ?> [] getRootConfigClasses() { // 配置Spring IoC资源 return new Class< ?> [] { RootConfig.class }; //获取Spring Ioc容器的java配置类,用以装载各类Spring Bean }// DispatcherServlet环境配置 @Override protected Class< ?> [] getServletConfigClasses() { // 加载Java配置类 return new Class< ?> [] { WebConfig.class }; //获取各类Spring MVC的URI和控制器的配置关系类 }// DispatchServlet拦截请求配置 @Override protected String[] getServletMappings() { return new String[] { "*.do" }; //定义DispatcherServlet拦截的请求 }/** * @param dynamic *Servlet上传文件配置. */ @Override protected void customizeRegistration(Dynamic dynamic) {//P443页 // 配置上传文件路径 String filepath = "e:/mvc/uploads"; // 限制请求单个文件5MB Long singleMax = (long) (5 * Math.pow(2, 20)); // 总文件10MB Long totalMax = (long) (10 * Math.pow(2, 20)); // 设置上传文件配置 dynamic.setMultipartConfig(new MultipartConfigElement(filepath, singleMax, totalMax, 0)); }}
推荐阅读
- uniApp——v-for 动态class动态style
- AndroidAndroid Studio真机调试的问题统整
- kibana提示"[illegal_argument_exception] mapper [hits] cannot be changed from type [long] to [inte
- Android广播的使用(自定义广播和本地广播)
- Android广播的使用(动态注册和静态注册)
- Hadoop| MapperReduce② 框架原理
- Qt Create 4.6.2无法自动生成Android Kit
- android studio如何获取SHA1(Win+Mac)
- ExecutorException: A query was run and no Result Maps were found for the Mapped Statement ‘com.win.m