springMVC 配置文件参考

<?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"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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
                http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
            
       <!-- 自动检测bean -->         
       <context:component-scan base-package="com.bupt.web.dao"/>
       <context:component-scan base-package="com.bupt.web.controller"/> 
       <context:component-scan base-package="com.bupt.web.service"/>
        
                
       <!-- springMVC开启注解 -->
	   <mvc:annotation-driven/>
	   
	   <!-- 静态资源加载 -->
	   <mvc:resources location="/resources/" mapping="/resources/**"/>
	   
	   <!-- 解析内部视图 -->
	   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	   		<!-- 使用JSTL标签 -->
	   		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
	   		<property name="prefix" value="/WEB-INF/pages"></property>
	   		<property name="suffix" value=".jsp"></property>
	   </bean>
	   
	   <!-- hibernate配置文件 -->
	   <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
            	<list>
                	<value>classpath:hibernate.properties</value>
            	</list>
            </property>
       </bean>   
        
        <!-- 声明Hibernate的Session工厂 -->
	    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
			<property name="dataSource" ref="dataSource"/>
			<property name="packagesToScan" value="com.bupt.web.bean"/>
			<property name="hibernateProperties">
				<props>
	                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
	                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
	                <prop key="hibernate.format_sql">true</prop>
	                <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
	                <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
	                <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
	                <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
	                <prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop>
	               
	          	</props>
		    </property>
		
	   </bean>
	   
	   <!-- 数据源配置 DBCP连接池 -->
	   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
			<!-- 连接信息 -->
			<property name="driverClassName" value="${jdbc.driver}" />
			<property name="url" value="${jdbc.url}" />
			<property name="username" value="${jdbc.username}" />
			<property name="password" value="${jdbc.password}" />
		
			<!-- 连接池信息 -->
			<property name="maxActive" value="${dbcp.maxActive}" />
			<property name="maxIdle" value="${dbcp.maxIdle}" />
			<property name="defaultAutoCommit" value="false" />
			<!-- 设置连接超时 -->
			<property name="timeBetweenEvictionRunsMillis" value="3600000" />
			<property name="minEvictableIdleTimeMillis" value="3600000" />
    	</bean> 
	   
	   <!-- 注解驱动事务 -->
	   <tx:annotation-driven transaction-manager="transactionManager"/>
	   
	   <!-- 配置事务管理器 -->
       <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        	<property name="sessionFactory" ref="sessionFactory"/>
       </bean>
       
       <!-- 上传文件配置 -->
       <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" >
			<property name="maxUploadSize">  
        		<value>1048576</value>  
    		</property>  
	   </bean>
	                     
</beans>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值