package com.mu.config;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebApplicationStartup implements WebApplicationInitializer {
private static final String SERVLET_NAME = "Spring-mvc";
private static final long MAX_FILE_UPLOAD_SIZE = 1024 * 1024 * 5; // 5 Mb
private static final int FILE_SIZE_THRESHOLD = 1024 * 1024; // After 1Mb
private static final long MAX_REQUEST_SIZE = -1L; // No request size limit
/**
* 服务器启动调用此方法,在这里可以做配置 作用与web.xml相同
*/
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// 注册springMvc的servlet
this.addServlet(servletContext);
// 注册过滤器
// servletContext.addFilter(arg0, arg1)
// 注册监听器
// servletContext.addListener(arg0);
}
/**
* 注册Spring servlet
*
* @param servletContext
*/
private void addServlet(ServletContext servletContext ) {
// 构建一个application context
AnnotationConfigWebApplicationContext webContext = createWebContext(SpringConfig.class, ViewConfiguration.class);
// 注册spring mvc 的 servlet
Dynamic dynamic = servletContext.addServlet(SERVLET_NAME, new DispatcherServlet(webContext));
// 添加springMVC 允许访问的Controller后缀
dynamic.addMapping("*.html", "*.ajax", "*.css", "*.js", "*.gif", "*.jpg", "*.png","*.do");
// 全部通过请用 “/”
// dynamic.addMapping("/");
dynamic.setLoadOnStartup(1);
dynamic.setMultipartConfig(new MultipartConfigElement(null, MAX_FILE_UPLOAD_SIZE, MAX_REQUEST_SIZE, FILE_SIZE_THRESHOLD));
}
/**
* 通过自定义的配置类来实例化一个Web Application Context
*
* @param annotatedClasses
* @return
*/
private AnnotationConfigWebApplicationContext createWebContext(Class<?>... annotatedClasses) {
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.register(annotatedClasses);
return webContext;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
springMVC零配置,无web.xml,无spring配置
共60个文件
jar:36个
java:6个
class:6个
4星 · 超过85%的资源 需积分: 48 42 下载量 173 浏览量
2017-02-09
15:26:30
上传
评论 1
收藏 22.77MB RAR 举报
温馨提示
springMVC零配置,无web.xml,无spring配置,纯java
资源推荐
资源详情
资源评论
收起资源包目录
JavaConfigSpringWebProject_MU.rar (60个子文件)
JavaConfigSpringWebProject_MU
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
com.genuitec.eclipse.core.prefs 90B
org.eclipse.wst.common.project.facet.core.xml 358B
org.eclipse.wst.common.component 546B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 522B
org.eclipse.jdt.core.prefs 364B
src
com
mu
config
ViewConfiguration.java 752B
WebApplicationStartup.java 2KB
SpringConfig.java 366B
test
MainAppTest.java 562B
bean
HelloWorld.java 243B
controller
TestController.java 654B
.project 1KB
WebRoot
META-INF
MANIFEST.MF 39B
WEB-INF
classes
com
mu
config
ViewConfiguration.class 1KB
WebApplicationStartup.class 3KB
SpringConfig.class 550B
test
MainAppTest.class 966B
bean
HelloWorld.class 818B
controller
TestController.class 1KB
jsp
hello_world.jsp 787B
lib
spring-webmvc-portlet-4.0.6.RELEASE.jar 172KB
commons-collections-3.1.jar 546KB
log4j.jar 349KB
validation-api-1.0.0.GA.jar 46KB
commons-beanutils-1.7.0.jar 184KB
spring-beans-4.0.6.RELEASE.jar 655KB
spring-core-4.0.6.RELEASE.jar 954KB
spring-jms-4.0.6.RELEASE.jar 206KB
spring-tx-4.0.6.RELEASE.jar 243KB
spring-context-4.0.6.RELEASE.jar 955KB
jboss-logging-3.2.1.Final.jar 65KB
spring-instrument-tomcat-4.0.6.RELEASE.jar 10KB
aspectj-1.7.3.jar 13.24MB
spring-expression-4.0.6.RELEASE.jar 201KB
ezmorph-1.0.3.jar 76KB
spring-build-src-4.0.6.RELEASE.jar 71KB
spring-instrument-4.0.6.RELEASE.jar 7KB
spring-jdbc-4.0.6.RELEASE.jar 415KB
spring-websocket-4.0.6.RELEASE.jar 274KB
spring-webmvc-4.0.6.RELEASE.jar 647KB
spring-context-support-4.0.6.RELEASE.jar 132KB
spring-test-4.0.6.RELEASE.jar 439KB
spring-web-4.0.6.RELEASE.jar 657KB
spring-messaging-4.0.6.RELEASE.jar 262KB
spring-orm-4.0.6.RELEASE.jar 359KB
spring-framework-bom-4.0.6.RELEASE.jar 6KB
aopalliance.jar 4KB
commons-fileupload-1.2.2.jar 58KB
commons-logging-1.2.jar 60KB
spring-oxm-4.0.6.RELEASE.jar 79KB
commons-lang-2.5.jar 273KB
json-lib-2.4-jdk15.jar 155KB
spring-aspects-4.0.6.RELEASE.jar 51KB
aspectjweaver-1.5.0.jar 1.67MB
hibernate-validator-4.3.0.Final.jar 465KB
spring-aop-4.0.6.RELEASE.jar 345KB
index.jsp 829B
.classpath 848B
共 60 条
- 1
资源评论
- Zeb-D2018-04-04为什么不maven管理
- nju.拈花2018-06-18不错,详细清晰。
雪夜里的孤狼
- 粉丝: 9
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功