[英]No local DataSource found for configuration - 'dataSource' property must be set on LocalSessionFactoryBean
I am using Spring 3.0 and Hibernate 3.6 我正在使用Spring 3.0和Hibernate 3.6
DataSource is defined as 数据源定义为
<bean id="test-pool"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url"
value="jdbc:sqlserver://Machine:1433;databaseName=TEST;maxPoolSize=100;
minPoolSize=5;acquireIncrement=5;checkoutTimeout=5000;maxStatements=100;idleConnectionTestPeriod=3000" />
<property name="username" value="${user}" />
<property name="password" value="${database.password}"/>
</bean>
Session Factory with data source is 具有数据源的会话工厂为
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="test-pool"/>
<property name="configLocation" value="WEB-INF/classes/test.hibernate.cfg.xml"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
</props>
</property>
</bean>
In Factory class: 在工厂班级:
LocalSessionFactoryBean localfactorybean = (LocalSessionFactoryBean)AppContext.getBean("&sessionFactory");
Configuration configuration = localfactorybean.getConfiguration();
SessionFactory sessionFactory = configuration.buildSessionFactory();
But I am getting following exception 但我正在追随异常
org.hibernate.HibernateException: No local DataSource found for configuration - 'dataSource' property must be set on LocalSessionFactoryBean
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.configure(LocalDataSourceConnectionProvider.java:49)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:84)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:459)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91)
What is wrong with my current code? 我当前的代码有什么问题?
I get rid of this exception if I explicitly get SessionFactory again like this: 如果我再次像这样显式地获取SessionFactory,我将摆脱此异常:
SessionFactory sessionFactory = (SessionFactory) AppContext.getBean("sessionFactory");
As you can see its not neat and I want to get rid of it. 如您所见,它不整洁,我想摆脱它。
What exact version of Hibernate are you using? 您使用的是什么版本的Hibernate? This article suggests that there is a problem with 3.2.1 which has the same symptoms as you have. 本文建议3.2.1出现问题,该问题与您的症状相同。 Maybe time to update your version - hibernate is now at 4.1.4 也许是时候更新版本了-休眠版本为4.1.4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.