SpringMvc的xml文件的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
                           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
	default-autowire="byName">


	<!-- 作用是式地向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、 
		PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 
		这 4 个BeanPostProcessor。 注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。 -->
	<context:annotation-config />

	<!-- 在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component 
		@Controller@Service等这些注解的类,则把这些类注册为bean -->
	<context:component-scan base-package="com.witon.ehealth.web" />

	<!-- <mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 
		两个bean,是spring MVC为@Controllers分发请求所必须的。 -->
	<mvc:annotation-driven />

	<!-- <bean id="handlerMapping" -->
	<!-- class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"> -->
	<!-- <property name="interceptors"> -->
	<!-- <bean class="com.witon.ehealth.web.interceptor.CommonInterceptor" /> -->
	<!-- </property> -->
	<!-- </bean> -->

	<bean id="notFoundController"
		class="com.witon.ehealth.web.contoller.error.NotFoundController" />

	<bean id="urlMapping"
		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="alwaysUseFullPath" value="true" />
		<property name="mappings">
			<props>
				<prop key="/**">notFoundController</prop>
			</props>
		</property>
		<property name="interceptors">
			<list>
				<!-- <ref bean="clientDataInterceptor" /> -->
				<!-- <ref bean="securityInterceptor" /> -->
				<!-- <ref bean="resourceCleanupInterceptor" /> -->
			</list>
		</property>
	</bean>


	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/**/*.htm" />
			<bean class="com.witon.ehealth.web.interceptor.CommonInterceptor" />
		</mvc:interceptor>
		<!-- <bean class="com.witon.ehealth.web.interceptor.CommonInterceptor" 
			/> -->
	</mvc:interceptors>


	<bean id="handlerExceptionResolver" class="com.witon.ehealth.web.config.DefaultExceptionResolver" />

	<!-- This bean sets up the Velocity environment for us based on a root path 
		for templates. Optionally, a properties file can be specified for more control 
		over the Velocity environment, but the defaults are pretty sane for file 
		based template loading. -->
	<bean id="velocityConfig"
		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="resourceLoaderPath" value="/WEB-INF/velocity/" />
		<property name="velocityProperties">
			<props>
				<prop key="input.encoding">utf-8</prop>
				<prop key="output.encoding">utf-8</prop>
				<prop key="velocimacro.library">macro/macro.vm</prop><!-- Velocimacro 模板库的列表 -->
			</props>
		</property>
	</bean>

	<bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="order" value="1" />

		<property name="defaultContentType" value="text/html" />

		<property name="mediaTypes">
			<map>
				<entry key="atom" value="application/atom+xml" />
				<entry key="json" value="application/json" />
				<entry key="xml" value="application/xml" />
				<entry key="a" value="application/xml" />
				<!-- <entry key="html" value="text/html" /> -->
				<!-- <entry key="html" value="application/x-www-form-urlencoded" /> -->
			</map>
		</property>
		<property name="viewResolvers">
			<list>

				<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

				<bean
					class="org.springframework.web.servlet.view.InternalResourceViewResolver">
					<property name="viewClass"
						value="org.springframework.web.servlet.view.JstlView" />
					<property name="viewNames">
						<list>
							<value>*.jsp</value>
						</list>
					</property>
					<property name="prefix" value="/WEB-INF/views/" />
				</bean>

				<bean
					class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
					<!-- <property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityView" 
						/> -->
					<property name="viewClass"
						value="org.springframework.web.servlet.view.velocity.VelocityToolbox20View" />

					<!-- 处理后缀为vm的视图 -->
					<property name="viewNames">
						<list>
							<value>*.vm</value>
						</list>
					</property>

					<!-- 使用springMacro、使用servlet的对象 -->
					<property name="exposeSpringMacroHelpers" value="true" />
					<property name="exposeRequestAttributes" value="true" />
					<property name="exposeSessionAttributes" value="true" />

					<property name="contentType" value="text/html;charset=UTF-8" />

					<property name="toolboxConfigLocation" value="classpath:/META-INF/velocity/toolbox.xml" />

					<property name="cache" value="true" />
				</bean>

				<bean
					class="org.springframework.web.servlet.view.InternalResourceViewResolver" />

			</list>
		</property>
		<property name="defaultViews">
			<list>
				<bean id="jsonView"
					class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
				<bean id="xmlView"
					class="org.springframework.web.servlet.view.xml.MarshallingView">
					<property name="marshaller">
						<bean class="org.springframework.oxm.xstream.XStreamMarshaller" />
					</property>
				</bean>
			</list>
		</property>
	</bean>

	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- one of the properties available; the maximum file size in bytes -->
		<property name="maxUploadSize" value="10000000" />
	</bean>

	<mvc:resources mapping="/static/**" location="/resources/" />

	<mvc:resources mapping="/js/**" location="/js/" />
	<mvc:resources mapping="/css/**" location="/css/" />
	<mvc:resources mapping="/img/**" location="/img/" />

	<mvc:resources mapping="/resources/**"
		location="classpath:/META-INF/public-web-resources/" cache-period="31556926" />

	<mvc:view-controller path="/" view-name="login.htm" />

        <!-- 对于静态资源部拦截,tomcat默认的是这个名字,各个服务器不一样的-->
	<!-- <mvc:default-servlet-handler /> -->

	<!-- tiles -->
	<!-- <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> -->
	<!-- <property name="definitions"> -->
	<!-- <list> -->
	<!-- <value>/WEB-INF/defs/general.xml</value> -->
	<!-- <value>/WEB-INF/defs/widgets.xml</value> -->
	<!-- <value>/WEB-INF/defs/administrator.xml</value> -->
	<!-- <value>/WEB-INF/defs/customer.xml</value> -->
	<!-- <value>/WEB-INF/defs/templates.xml</value> -->
	<!-- </list> -->
	<!-- </property> -->
	<!-- </bean> -->


</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值