Reputation: 1489
this is my ApplicationContext.xml. I can't run my program because of this error:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [ApplicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError
I must say that HibernateVoc extends HibernateDaoSupport. I've looked at several web pages in search of how to use HibernateDaoSupport, wether these are the correct properties to initialize sessionFactory... I've not managed how to work out the problem.
Thanks y'all!
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.gjt.mm.mysql.Driver" />
<property name="url" value="jdbc:mysql://localhost/voc" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="mappingResources">
<list>
<value>com/ju/voc/domain/words/Word.hbm.xml</value>
<value>com/ju/voc/domain/categroies/Category.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<bean id="hibernateVoc" class="com.ju.voc.data.HibernateVoc">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
P.S. I'm using Maven, so I download libraries from there.
Upvotes: 3
Views: 8408
Reputation: 299178
You are missing the dependency to hibernate.
Because the spring-orm
artifact handles ORM using plain Hibernate, JPA, JDO and iBatis (and it hardly ever makes sense to use them all), all of these depenencies are marked as optional, which means that you have to reference the dependencies in your pom.xml. Here's how to reference the latest stable version of hibernate core:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.7.Final</version>
</dependency>
Upvotes: 6
Reputation: 13792
The exception you got (java.lang.NoClassDefFoundError) means that you forgot to include a library jar in your application. Try to deep analyze the log trace, and find the missing class in order to include the proper jar. Probably you missed hibernate dependency.
Upvotes: 3