spring mvc+hibernate的基本配置

<?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:p="http://www.springframework.org/schema/p"

    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"

    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/tx 

                        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 

                        http://www.springframework.org/schema/aop  

                        http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

                        http://www.springframework.org/schema/mvc 

                        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">



    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>

        <property name="jdbcUrl"

            value="jdbc:mysql://localhost/dbname?useUnicode=true&amp;characterEncoding=utf-8">

        </property>

        <property name="user" value="root"></property>

        <property name="password" value="root"></property>

        <property name="minPoolSize" value="10"></property>

        <property name="maxPoolSize" value="50"></property>

        <property name="maxIdleTime" value="1800"></property>

        <property name="initialPoolSize" value="25"></property>

        <property name="idleConnectionTestPeriod" value="1800"></property>

        <property name="acquireRetryAttempts" value="30"></property>

        <property name="breakAfterAcquireFailure" value="true"></property>

        <property name="testConnectionOnCheckout" value="false"></property>

    </bean>



    <bean id="sessionFactory"

        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="hibernateProperties">

            <props>

                <prop key="hibernate.dialect">

                    org.hibernate.dialect.MySQL5Dialect

                </prop>

                <prop key="hibernate.show_sql">

                    false

                </prop>

                <prop key="hibernate.hbm2ddl.auto">update</prop>

                <prop key="hibernate.current_session_context_class">

                    org.springframework.orm.hibernate4.SpringSessionContext

                </prop>

                <prop key="hibernate.jdbc.fetch_size">16</prop>

                <prop key="hibernate.jdbc.batch_size">20</prop>

                <prop key="hibernate.default_batch_fetch_size">10</prop>

                <prop key="use_second_level_cache">false</prop>

                <prop key="use_query_cache">false</prop>

            </props>

        </property>

        <property name="dataSource" ref="dataSource" />

        <property name="packagesToScan">

            <list>

                <value>com.abc</value>

            </list>

        </property>

    </bean>





    <!-- 配置事务管理器 -->

    <bean id="transactionManager"

        class="org.springframework.orm.hibernate4.HibernateTransactionManager">

        <property name="sessionFactory" ref="sessionFactory" />

        <property name="dataSource" ref="dataSource" />

    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />





    <!--默认的注解映射的支持 -->

    <mvc:annotation-driven />



    <context:component-scan base-package="com.abc" />

    <aop:aspectj-autoproxy/>

    <bean id="multipartResolver"

        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

        <property name="defaultEncoding" value="utf-8"></property>

    </bean>



    <bean id="jspViewResolver"

        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="viewClass"

            value="org.springframework.web.servlet.view.JstlView" />

        <property name="prefix" value="/WEB-INF/jsp/" />

        <property name="suffix" value=".jsp" />

        <property name="order" value="1" />

    </bean>

<!--加载property-->   <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath*:system.properties</value> </list> </property> </bean> </beans>

 

你可能感兴趣的:(spring mvc)