<?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:tx=" http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" default-autowire="byName"> <!-- 为dataSource指定jdbc.properties文件的位置 --> <bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> </bean> <!-- 配置 BoneCP 数据源 --> <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driverClassName}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!-- 设置测试connection的间隔时间。这个参数默认为240,单位:分钟。设置为0该功能失效。 --> <property name="idleConnectionTestPeriod" value="60"/> <!-- 设置connection的空闲存活时间。这个参数默认为60,单位:分钟。设置为0该功能失效。 --> <property name="idleMaxAge" value="240"/> <!--每个分区最大connection数 --> <property name="maxConnectionsPerPartition" value="60"/> <!-- 每个分区最小connection数 --> <property name="minConnectionsPerPartition" value="20"/> <!-- 设置分区个数。这个参数默认为1,建议3-4 --> <property name="partitionCount" value="3"/> <!-- 设置分区中的connection增长数量。这个参数默认为1 --> <property name="acquireIncrement" value="10"/> <property name="statementsCacheSize" value="50"/> <property name="releaseHelperThreads" value="3"/> </bean> <!-- Hibernate配置 、 sessionFactory --> <bean name="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.current_session_context_class">thread</prop> </props> </property> <property name="packagesToScan"> <list> <value>com.nes.vo.admin</value> </list> </property> </bean> <!-- 事务 begin --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="sel*" read-only="true" /> <tx:method name="save*" /> <tx:method name="del*" /> </tx:attributes> </tx:advice> <!-- 事务 end --> <!-- Inject DAO --> <bean name="basicDAO" class="com.nes.dao.BasicDAO"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> </beans>
package com.nes.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; public class BasicDAO { private SessionFactory sessionFactory; private Session session; public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public Session getSession() { return sessionFactory.getCurrentSession(); } public void setSession(Session session) { this.session = session; } }
我用Junit测试了 SF一直是空的....
请大家帮我看看吧~~~~