<?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: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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 自动扫描注解的  bean 并装配 -->
<context:component-scan base-package="cn.itcast.oa"></context:component-scan>


<!-- 配置SessionFactory(与hibernate整合) -->
<context:property-placeholder location="classpath:jdbc.properties"/><!-- 配置文件得位置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 指定hibernate配置文件得位置 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 配置数据源 DataSource -->
<property name="dataSource">
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 数据库得连接信息 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${username}"></property>
<property name="password" value="${password}"></property>
<!-- 其他一些配置 -->
<property name="initialPoolSize" value="3"></property>
<property name="minPoolSize" value="3"></property>
<property name="maxPoolSize" value="15"></property>
<property name="acquireIncrement" value="3"></property>
<property name="maxStatements" value="8"></property>
<property name="maxStatementsPerConnection" value="5"></property>
<property name="maxIdleTime" value="1800"></property>
</bean>
</property>
</bean>

<!-- 配置声明式事务,使用基于注解得方式 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFacaory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>


</beans>在我想试一下声明事务是否成功,就在一个类中
private ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
@Test
public void testSessionFactory(){
SessionFactory sessionFactory = (SessionFactory) ac.getBean("sessionFactory");
System.out.println(sessionFactory.openSession());

}
这么写,结果提示我
No bean named 'sessionFacaory' is defined