首页 > 代码库 > 一个非常棒的SpringMVC配置文件
一个非常棒的SpringMVC配置文件
1 <beans 2 xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:tx="http://www.springframework.org/schema/tx" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:mvc="http://www.springframework.org/schema/mvc" 7 xsi:schemaLocation="http://www.springframework.org/schema/beans 8 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 9 http://www.springframework.org/schema/tx 10 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 11 http://www.springframework.org/schema/context 12 http://www.springframework.org/schema/context/spring-context-3.0.xsd 13 http://www.springframework.org/schema/mvc 14 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 15 16 17 <!-- 自动扫描包,可以写多个 --> 18 <context:component-scan base-package="com.xxx,com.xxx.session,com.xxx.xxx" ></context:component-scan> 19 20 <!-- 多视图处理器 --> 21 <bean class="com.xxx.core.web.MixedViewResolver"> 22 <property name="resolvers"> 23 <map> 24 <entry key="jsp"> 25 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 26 <property name="prefix" value="/WEB-INF/jsp/"/> 27 <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> 28 </bean> 29 </entry> 30 <entry key="ftl"> 31 <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> 32 <property name="cache" value="true"/> 33 <property name="contentType" value="text/html;charset=UTF-8"></property> 34 <!-- 宏命令的支持 --> 35 <property name="exposeSpringMacroHelpers" value="true"/> 36 <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/> 37 <property name="requestContextAttribute" value="rc"></property> 38 </bean> 39 </entry> 40 </map> 41 </property> 42 </bean> 43 44 <!-- freemarker config --> 45 <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> 46 <property name="templateLoaderPath" value="/WEB-INF/ftl/" /> 47 <property name="freemarkerSettings"> 48 <props> 49 <prop key="template_update_delay">5</prop> 50 <prop key="default_encoding">UTF-8</prop> 51 <prop key="locale">zh_CN</prop> 52 </props> 53 </property> 54 </bean> 55 56 <!-- 日志拦截器--> 57 <bean id="logNDCInteceptor" class="com.xxx.core.web.LogNDCInteceptor"/> 58 59 <!-- 权限拦截器--> 60 <bean id="myPermissionsInteceptor" class="com.xxx.userplatform.mvc.MyPermissionsInteceptor"></bean> 61 62 <!-- RequestHelper拦截器--> 63 <bean id="myRequestHelperInteceptor" class="com.xxx.core.web.MyRequestHelperInteceptor"></bean> 64 65 <!-- 用户信息拦截器--> 66 <bean id="myUserInfoInteceptor" class="com.xxx.userplatform.mvc.MyUserInfoInteceptor"></bean> 67 68 <!-- 注解请求映射 --> 69 <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 70 <property name="interceptors"> 71 <list> 72 <ref bean="logNDCInteceptor"/> <!-- 日志拦截器 --> 73 <ref bean="myRequestHelperInteceptor"/> <!-- RequestHelper拦截器--> 74 <ref bean="myPermissionsInteceptor"/> <!-- 权限拦截器--> 75 <ref bean="myUserInfoInteceptor"/> <!-- 用户信息拦截器--> 76 </list> 77 </property> 78 </bean> 79 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 80 <property name="messageConverters"> 81 <list> 82 <ref bean="byteArray_hmc" /> 83 <ref bean="string_hmc" /> 84 <ref bean="resource_hmc" /> 85 <ref bean="source_hmc" /> 86 <ref bean="xmlAwareForm_hmc" /> 87 <ref bean="jaxb2RootElement_hmc" /> 88 <ref bean="jackson_hmc" /> 89 </list> 90 </property> 91 </bean> 92 <bean id="byteArray_hmc" class="org.springframework.http.converter.ByteArrayHttpMessageConverter" /><!-- 处理.. --> 93 <bean id="string_hmc" class="org.springframework.http.converter.StringHttpMessageConverter" /><!-- 处理.. --> 94 <bean id="resource_hmc" class="org.springframework.http.converter.ResourceHttpMessageConverter" /><!-- 处理.. --> 95 <bean id="source_hmc" class="org.springframework.http.converter.xml.SourceHttpMessageConverter" /><!-- 处理.. --> 96 <bean id="xmlAwareForm_hmc" class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /><!-- 处理.. --> 97 <bean id="jaxb2RootElement_hmc" class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" /><!-- 处理.. --> 98 <bean id="jackson_hmc" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /><!-- 处理json--> 99 100 101 <!-- 总错误处理-->102 <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">103 104 <property name="exceptionMappings"> 105 <props> 106 <!-- 上传文件大于最大尺寸后转向出错页面 --> 107 <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException"> 108 redirect:/uploadError.jsp109 </prop> 110 </props> 111 </property> 112 <property name="defaultErrorView"> 113 <value>forward:/error.jsp</value>114 </property>115 <property name="defaultStatusCode"> 116 <value>200</value>117 </property> 118 <property name="warnLogCategory"> 119 <value>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver</value>120 </property> 121 122 </bean> 123 124 <!-- 允许对静态资源文件的访问 --> 125 <mvc:default-servlet-handler/>126 127 <!-- 数据源 ,DBCP连接池-->128 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">129 <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>130 <property name="url" value="jdbc:oracle:thin:@192.168.3.141:1521:xxx"/>131 <property name="username" value="xxxdb"/>132 <property name="password" value="xxxdb"/>133 <property name="initialSize" value="2"/>134 <property name="maxActive" value="10"/>135 <property name="maxIdle" value="10"/>136 <property name="maxWait" value="1000"/>137 <property name="poolPreparedStatements" value="true"/>138 </bean>139 140 <!-- JNDI数据源141 <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">142 <property name="jndiName">143 <value>jdbc/xxx</value>144 </property>145 </bean>146 -->147 148 <!-- JDBC模板 -->149 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >150 <property name="dataSource" ref="dataSource" />151 </bean>152 <!-- 事务管理器 -->153 <bean id="transactionManager"154 class="org.springframework.jdbc.datasource.DataSourceTransactionManager">155 <property name="dataSource" ref="dataSource" />156 </bean>157 <!-- 用注解来实现事务管理 -->158 <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>159 160 <!-- 用于持有ApplicationContext,可以使用SpringContextHolder.getBean(‘xxxx‘)的静态方法得到spring bean对象 --> 161 <bean class="com.xxxxx.SpringContextHolder" lazy-init="false" /> 162 163 </beans>
一个非常棒的SpringMVC配置文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。