我是Hibernate的新手,并尝试运行一个java / spring示例,该示例从MS SqlServer中的表中检索数据。每次我尝试运行程序时,数据源都会加载。但是当spring尝试加载会话facotry时会出现以下错误:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory'
defined in class path resource [ml/spring/src/applicationContext.xml]:
Instantiation of bean failed; nested exception is
java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
Caused by: java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
以下是我正在使用的应用程序上下文文件:
<!-- Data source bean -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName">
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value></property>
<property name="url">
<value>jdbc:microsoft:sqlserver://machine:port</value></property>
<property name="username"><value>user</value></property>
<property name="password"><value>password</value></property>
</bean>
<!-- Session Factory Bean -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>authors.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect
</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
答案 0 :(得分:14)
您缺少包含JTA API类的JAR文件。您下载Hibernate时可能已经有一个。它应该被称为:
jta-1.1.jar
希望这有帮助。
答案 1 :(得分:0)
如果您使用的是maven,请使用this,
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>