[英]No local DataSource found for configuration - 'dataSource' property must be set on LocalSessionFactoryBean
我正在使用Spring 3.0和Hibernate 3.6
數據源定義為
<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>
具有數據源的會話工廠為
<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>
在工廠班級:
LocalSessionFactoryBean localfactorybean = (LocalSessionFactoryBean)AppContext.getBean("&sessionFactory");
Configuration configuration = localfactorybean.getConfiguration();
SessionFactory sessionFactory = configuration.buildSessionFactory();
但我正在追隨異常
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)
我當前的代碼有什么問題?
如果我再次像這樣顯式地獲取SessionFactory,我將擺脫此異常:
SessionFactory sessionFactory = (SessionFactory) AppContext.getBean("sessionFactory");
如您所見,它不整潔,我想擺脫它。
您使用的是什么版本的Hibernate? 本文建議3.2.1出現問題,該問題與您的症狀相同。 也許是時候更新版本了-休眠版本為4.1.4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.