applicationContext.xml

来源:互联网 发布:java定义整形变量关键 编辑:程序博客网 时间:2024/06/05 12:41
<?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:aop="http://www.springframework.org/schema/aop"   
        xmlns:context="http://www.springframework.org/schema/context"  
        xmlns:jee="http://www.springframework.org/schema/jee"  
        xmlns:tx="http://www.springframework.org/schema/tx"  
        xsi:schemaLocation="    
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd  
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd  
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd  
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

    <!-- 引入外部属性文件 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!-- 配置C3P0连接池: -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>
        <!-- 每20秒检查所有连接池中的空闲连接 -->
        <property name="idleConnectionTestPeriod" value="3"></property>
        <!-- 最大空闲时间,30秒内未使用则连接被丢弃。若为0则永不丢弃 -->
        <property name="maxIdleTime" value="5"></property>
        <!-- 最大连接数 -->
        <property name="maxPoolSize" value="20"></property>
    </bean>
    
    
    <!-- Hibernate的相关信息 -->

    <!--

    默认情况下,从bean工厂所取得的实例为Singleton(单例)

    假如没有scope="prototype",spring创建实例是采用单例
     -->
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <!-- 不采用数据库连接池C3P0,纯手动获取连接(连接不会释放)
        <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
         -->
        <!-- 注入连接池(1、提前获取连接    2、维护好hibernate给丢弃的连接) -->
        <property name="dataSource" ref="dataSource"/>
        
        <!-- 配置Hibernate的其他的属性 -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.connection.autocommit">false</prop>
                <!-- 开机自动生成表 -->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>Bean/product.hbm.xml</value>
            </list>
        </property>
        
    </bean>    

    <bean id="indexAction" class="Action.ItemsAction" scope="prototype">
        <property name="ser" ref="myIndexService"></property>
    </bean>
    
    <bean id="myIndexService" class="Service.Service" scope="prototype">
        <property name="dao" ref="myIndexDao"></property>
    </bean>
    
    <bean id="myIndexDao" class="Dao.Dao" scope="prototype">
        <property name="sessionfactory" ref="mySessionFactory"></property>
    </bean>
    

</beans>
0 0
原创粉丝点击