Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory with mybatis and Spring

I'm new to Mybatis and trying to implement mybatis with Spring but getting the below runtime error while starting tomcat.

Here is my pom.xml

<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.0.0</version>
</dependency>

and application context:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="uactivityDS"/>
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>

The error is:

the resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory

The mybatis-spring-1.0.0.jar file exists in war/web-inf/lib, though.

Any idea what's going on in this scenario?

like image 377
TP_JAVA Avatar asked Jul 02 '12 21:07

TP_JAVA


1 Answers

If you look at the pom.xml for mybatis-spring-1.0.0.jar, it has a compile time dependency of mybatis 3.0.4 which contains the class org/apache/ibatis/session/SqlSessionFactory.

So include that jar as well along with others mentioned in the pom.xml and you should be good.

like image 87
Ravi Kadaboina Avatar answered Oct 14 '22 05:10

Ravi Kadaboina