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: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> [size=xx-small][/size]

你可能感兴趣的:(spring)