2 qq 14851021 qq_14851021 于 2016.09.18 11:39 提问

我这个spring 和mybatis组合出现这个问题怎么解决 找资料了也解决不了
 <bean id="dbcp" 
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="username" value="root">
    </property>
    <property name="password" value="1234">
    </property>
    <property name="driverClassName"
        value="com.mysql.jdbc.Driver">
    </property>
    <property name="url" 
        value="jdbc:mysql:///cloud_note?useUnicode=true&amp;characterEncoding=utf8">
    </property>
</bean>

<bean id="ssf" 
    class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dbcp">
    </property>
    <property name="mapperLocations" 
        value="classpath:org/tarena/note/sql/*.xml">
    </property>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" 
        value="org.tarena.note.dao">
    </property>
    <!-- 自动注入sqlsessionfactory -->
</bean>

<!-- 开启扫描,扫描Controller,Service组件 -->
<context:component-scan 
    base-package="org.tarena.note"/>

<!-- handlermapping,支持@RequestMapping,@ResponseBody,@Exceptionhanlder -->
<mvc:annotation-driven />

严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:438)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:624)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:602)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:521)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1282)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1195)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1085)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5318)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5610)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1259)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1998)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory

5个回答

Evankaka
Evankaka   Ds   Rxr 2016.09.18 13:09
已采纳

Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory
mybatis的jar包引入了没?把整个工程clean一下再强制maven->update

qq_14851021
qq_14851021 F12说是找不到http://localhost8080/cloud_note/notebook/loadbooks.do样问题是出在哪里呢?
大约一年之前 回复
qq_14851021
qq_14851021 谢谢 好像是包的问题 不过输入http://localhost8080/cloud_note/notebook/loadbooks.do网页一片白,F12也没提示
大约一年之前 回复
of214
of214   2016.09.18 12:35

应该是配置问题,spring mybatis整合文章 http://58coding.com/article/detail/24659963087429989

qq_14851021
qq_14851021 F12说是找不到http://localhost8080/cloud_note/notebook/loadbooks.do问题是出在哪里呢?
大约一年之前 回复
qq_14851021
qq_14851021 谢谢 好像是包的问题 不过输入http://localhost8080/cloud_note/notebook/loadbooks.do网页一片白,F12也没提示
大约一年之前 回复
qq_14851021
qq_14851021   2016.09.18 11:43

class="org.apache.commons.dbcp.BasicDataSource">




value="com.mysql.jdbc.Driver">

value="jdbc:mysql:///cloud_note?useUnicode=true&characterEncoding=utf8">

class="org.mybatis.spring.SqlSessionFactoryBean">


value="classpath:org/tarena/note/sql/*.xml">


value="org.tarena.note.dao">

<!-- 自动注入sqlsessionfactory -->

base-package="org.tarena.note"/>


qq_14851021
qq_14851021   2016.09.18 11:44
 <bean id="dbcp" 
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="username" value="root">
    </property>
    <property name="password" value="1234">
    </property>
    <property name="driverClassName"
        value="com.mysql.jdbc.Driver">
    </property>
    <property name="url" 
        value="jdbc:mysql:///cloud_note?useUnicode=true&amp;characterEncoding=utf8">
    </property>
</bean>

<bean id="ssf" 
    class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dbcp">
    </property>
    <property name="mapperLocations" 
        value="classpath:org/tarena/note/sql/*.xml">
    </property>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" 
        value="org.tarena.note.dao">
    </property>
    <!-- 自动注入sqlsessionfactory -->
</bean>

<!-- 开启扫描,扫描Controller,Service组件 -->
<context:component-scan 
    base-package="org.tarena.note"/>

<!-- handlermapping,支持@RequestMapping,@ResponseBody,@Exceptionhanlder -->
<mvc:annotation-driven />
qq_14851021
qq_14851021   2016.09.18 11:45

上面是我的applicationContext.xml的内容,<beans xmlns=的内容我没复制过来

Csdn user default icon
上传中...
上传图片
插入图片