当前位置:编程学习 > JAVA >>

spring中配置文件出错,看不懂麻烦各位帮帮忙

<?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 --------------------编程问答-------------------- 哦,让我想起了 火龙果 为什么退出csdn了 --------------------编程问答-------------------- getBean()方法的参数是name而不是id,再配置一个name --------------------编程问答-------------------- No bean named 'sessionFacaory' is defined
提示名字是name没有! --------------------编程问答-------------------- 各种检查,各种马虎。要命了 --------------------编程问答-------------------- 你配置的是sessionFactory 注入的却是sessionFacaory 粗心害死人。 --------------------编程问答-------------------- sessionFacaory....这单词真帅气   --------------------编程问答-------------------- --------------------编程问答-------------------- 拼写错误很无语 --------------------编程问答-------------------- lz要仔细一点哦。
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,