`

Spring MVC配置文件

阅读更多
<?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:tx="http://www.springframework.org/schema/tx"
	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.0.xsd 
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
	http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    

    <!-- 自动扫描包,可以写多个 -->
    <context:component-scan base-package="com.xxx,com.xxx.session,com.xxx.xxx" ></context:component-scan>
    
    <!-- 多视图处理器 -->
    <bean class="com.xxx.core.web.MixedViewResolver">
		<property name="resolvers">
			<map>
				<entry key="jsp">
					<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
						<property name="prefix" value="/WEB-INF/jsp/"/>
						<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
					</bean>
				</entry>
				<entry key="ftl">
					<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
						<property name="cache" value="true"/>
						<property name="contentType" value="text/html;charset=UTF-8"></property>
						<!-- 宏命令的支持  -->  
						<property name="exposeSpringMacroHelpers" value="true"/>
						<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
						<property name="requestContextAttribute" value="rc"></property>
					</bean>
				</entry>
			</map>
		</property>
	</bean>
	
	<!-- freemarker config -->
    <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> 
        <property name="templateLoaderPath" value="/WEB-INF/ftl/" /> 
        <property name="freemarkerSettings"> 
            <props> 
                <prop key="template_update_delay">5</prop> 
                <prop key="default_encoding">UTF-8</prop> 
                <prop key="locale">zh_CN</prop> 
            </props> 
        </property> 
    </bean> 
    
    <!-- 日志拦截器-->
    <bean id="logNDCInteceptor" class="com.xxx.core.web.LogNDCInteceptor"/>
    
    <!-- 权限拦截器-->
    <bean id="myPermissionsInteceptor" class="com.xxx.userplatform.mvc.MyPermissionsInteceptor"></bean>
    
    <!-- RequestHelper拦截器-->
    <bean id="myRequestHelperInteceptor" class="com.xxx.core.web.MyRequestHelperInteceptor"></bean>
    
    <!-- 用户信息拦截器-->
    <bean id="myUserInfoInteceptor" class="com.xxx.userplatform.mvc.MyUserInfoInteceptor"></bean>
    
    <!-- 注解请求映射  -->
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">        
		<property name="interceptors">
		    <list>  
		    	<ref bean="logNDCInteceptor"/>   <!-- 日志拦截器 -->
		    	<ref bean="myRequestHelperInteceptor"/>   <!-- RequestHelper拦截器--> 
		    	<ref bean="myPermissionsInteceptor"/>  <!-- 权限拦截器--> 
		    	<ref bean="myUserInfoInteceptor"/>  <!-- 用户信息拦截器--> 
		    </list>        
		</property>        
	</bean>  	
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">  
			<list>  
				<ref bean="byteArray_hmc" />  
				<ref bean="string_hmc" />  
				<ref bean="resource_hmc" />  
				<ref bean="source_hmc" />  
				<ref bean="xmlAwareForm_hmc" />  
				<ref bean="jaxb2RootElement_hmc" />  
				<ref bean="jackson_hmc" />  
			</list>  
		</property>  
	</bean>  
	<bean id="byteArray_hmc" class="org.springframework.http.converter.ByteArrayHttpMessageConverter" /><!-- 处理.. -->
	<bean id="string_hmc" class="org.springframework.http.converter.StringHttpMessageConverter" /><!-- 处理.. -->
	<bean id="resource_hmc" class="org.springframework.http.converter.ResourceHttpMessageConverter" /><!-- 处理.. -->
	<bean id="source_hmc" class="org.springframework.http.converter.xml.SourceHttpMessageConverter" /><!-- 处理.. -->
	<bean id="xmlAwareForm_hmc" class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /><!-- 处理.. -->
	<bean id="jaxb2RootElement_hmc" class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" /><!-- 处理.. -->
	<bean id="jackson_hmc" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /><!-- 处理json-->
	
	
	<!-- 总错误处理-->
	<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		
		<property name="exceptionMappings"> 
			<props> 
			<!-- 上传文件大于最大尺寸后转向出错页面 --> 
				<prop key="org.springframework.web.multipart.MaxUploadSizeExceededException"> 
					redirect:/uploadError.jsp
				</prop> 
			</props> 
		</property> 
		<property name="defaultErrorView">  
		 	<value>forward:/error.jsp</value>
		</property>
		<property name="defaultStatusCode">  
		 	<value>200</value>
		</property>		 	
		<property name="warnLogCategory">  
		 	<value>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver</value>
		</property>		 	
		
	</bean> 
	
	<!-- 允许对静态资源文件的访问 --> 
	<mvc:default-servlet-handler/>

	<!-- 数据源 ,DBCP连接池-->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
		<property name="url" value="jdbc:oracle:thin:@192.168.3.141:1521:xxx"/>
		<property name="username" value="xxxdb"/>
		<property name="password" value="xxxdb"/>
		<property name="initialSize" value="2"/>
		<property name="maxActive" value="10"/>
		<property name="maxIdle" value="10"/>
		<property name="maxWait" value="1000"/>
		<property name="poolPreparedStatements" value="true"/>
	</bean>
	
	<!-- JNDI数据源
	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>jdbc/xxx</value>
		</property>
	</bean>
	-->
	
	<!-- JDBC模板 -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 用注解来实现事务管理 -->
	<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
	
    <!-- 用于持有ApplicationContext,可以使用SpringContextHolder.getBean('xxxx')的静态方法得到spring bean对象 -->  
    <bean class="com.xxxxx.SpringContextHolder" lazy-init="false" />  
	
</beans>
分享到:
评论

相关推荐

    spring mvc的配置文件详解

    简单的描述了spring mvc的配置示例,不包括注解方法和示例代码

    spring MVC 配置文档

    加载 DispatcherServlet 时 Spring 会尝试读取配置文件 默认的配置文件位于 web.xml 相同的路径下 文件名与注册的 Servlet 名有关 Servlet注册名跟上 -servlet.xml 例如:上面的 Servlet 注册名为 ...

    Spring MVC开发配置文件 applicationContext

    Spring Web MVC开发 xml配置文件格式,无bean之类 Spring Web MVC开发配置文件 applicationContext

    Spring-MVC配置文件

    spring-mvc的配置文件,用于SSM框架的配置文件,页面跳转

    Spring MVC入门教程

    十六、spring mvc 关于写几个配置文件的说明 十七、spring mvc 如何取得Spring管理的bean 十八、spring mvc 多视图控制器 十九、 &lt;mvc:annotation-driven /&gt; 到底做了什么工作 二十、 本文中springMVC.xml配置文件是...

    Spring MVC 入门实例

    上面, 我们在 web.xml 文件中告诉 ContextLoaderListener, 我们还有另外两个配置文件 /WEB-INF/database.xml 和 /WEB-INF/applicationContext.xml. applicationContext.xml: 1 2 &lt;!DOCTYPE beans PUBLIC "-//...

    Spring MVC+MyBatis开发从入门到项目实战

    第2篇是MyBatis技术入门,包括剖析JDBC的弊端、MyBatis的背景介绍、入门程序的编写、配置文件的剖析、高级映射及缓存结构的讲解,最后还介绍了MyBatis与Spring框架的整合。第3篇是Spring MVC技术入门,包括Spring ...

    Spring MVC 教程 快速入门 深入分析

    Spring MVC 教程 快速入门 深入分析 ...十六、spring mvc 关于写几个配置文件的说明 十七、spring mvc 如何取得Spring管理的bean 十八、spring mvc 多视图控制器 十九、 &lt;mvc:annotation-driven /&gt; 到底做了什么工作

    SSM框架的配置搭建 spring、 spring mvc、 mybatis 整合详解

    SSM框架的配置搭建 spring、 spring mvc、 mybatis 整合详解

    SpringMVC框架架构介绍

    十六、spring mvc 关于写几个配置文件的说明 十七、spring mvc 如何取得Spring管理的bean 十八、spring mvc 多视图控制器 十九、 &lt;mvc:annotation-driven /&gt; 到底做了什么工作 二十、 本文中springMVC.xml配置文件...

    SpringMVC和Spring的配置文件扫描包详解

    主要介绍了SpringMVC和Spring的配置文件扫描包,本文给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下

    spring mvc项目

    spring mvc maven项目,导入IDEA后无报错,需要在IDEA中...该项目使用servlet3.0规范,无web.xml,无spring.xml等配置文件,所有的配置均通过Java Config、注解搞定,项目中还集成了log4j2技术,以及前端html文件等。

    springmvc + spring + mybatis + maven整合配置文件

    springmvc + spring + mybatis + maven整合配置文件

    Spring MVC配置文档及原理介绍

    基于spring2.5的采用XML配置的spring MVC项目 基于spring2.5注解实现的spring MVC项目 基于spring 3.0项目开发实例 基于spring 3.0mvc 框架的文件上传实现 Spring中的拦截器

    spring xml配置文件思维导图

    自己总结的spring xml配置的思维导图,包括了spring的基础配置

    SpringMVC配置文件

    SpringMVC配置文件,自动扫描controller包下的所有类,开启注解功能

    Java开发基于SSM框架开发的客户管理系统源码.zip

    在项目文件夹下的config文件夹中包含数据库常量配置文件,spring配置文件,MyBatis配置文件,log4j配置文件,资源配置文件以及Spring MVC配置文件,其中数据库常量配置文件为db.properties以及MyBatis配置文件...

    spring mvc项目创建

    spring mvc项目的创建,项目文件的配置。

    Spring配置文件集合

    Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合

    Spring数据源及配置文件数据加密实现过程详解

    主要介绍了Spring数据源及配置文件数据加密实现过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics