Spring-mvc配置文件

本文详细介绍了Spring MVC中的组件扫描配置、如何设置视图解析器以及如何配置文件上传限制。重点讲解了`@Component`、`InternalResourceViewResolver`和`CommonsMultipartResolver`的作用。
摘要由CSDN通过智能技术生成
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
	"http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/mvc
	http://www.springframework.org/schema/mvc/spring-mvc.xsd" >
 
 	<!-- 
 		Spring扫描咱们的包 
 			Spring会把扫描咱们配置的包下面的所有类
 			如果发现类上面有 @Component, @Repository, @Service, @Controller 就会把这个类变成一个bean对象
 			 @Component:你不知道放哪一层,就用它
 			 @Repository【仓库】 :数据层(dao)中的类使用
 			 @Service:业务层使用
 			 @Controller : 控制层使用
 	-->
 	<context:component-scan base-package="cn.itsource" />
 	
 	<!-- 视图解析器 -->
	<bean id="resourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
	
	<!--
 	 SpringMVC默认把自己的注解支持关闭
 		 配置下面这个就可以把它打开
 	 -->
 	<mvc:annotation-driven />
 	
 	<!-- 静态资源放行 只要配置了这个,就可以访问图片,样式,音频等 -->
	<mvc:default-servlet-handler/>
	
	<!-- 配置一个上传解析器(拷备) 只针对一些小文件
	 multipart:附件
		注:id只能叫multipartResolver
	-->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 设置上传文件的最大尺寸为1MB -->
		<property name="maxUploadSize">
			<!-- spring el写法:1MB -->
			<value>#{1024*1024*5}</value>
		</property>
	     <!-- 效果同上 -->
		 <!--<property name="maxUploadSize" value="1048576" /> -->
	</bean>
	
	<!--配置Spring-mvc的拦截器    interceptor拦截器 -->
	<!-- <mvc:interceptors>
		
			拦截的请求路径
				/*只拦截一层请求
				/**拦截多级请求
		 
		 某个拦截器 
		<mvc:interceptor>
		
			多级拦截 
			<mvc:mapping path="/**"/>
			
			不拦截 
			<mvc:exclude-mapping path=""/>
			
			
			<bean class="cn.itsource.interceptor.Interceptor"></bean>
		</mvc:interceptor>
	</mvc:interceptors> -->
</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值