将Spring与MyBatis一起使用时出现Java异常

将Spring与MyBatis一起使用时出现Java异常,java,spring,mybatis,spring-3,spring-mybatis,Java,Spring,Mybatis,Spring 3,Spring Mybatis,我在进入httpInvoker后遇到异常,看起来如下: INFO: Initializing Spring FrameworkServlet 'httpInvoker' pro 23, 2015 4:34:04 PM org.apache.catalina.core.ApplicationContext log SEVERE: StandardWrapper.Throwable java.lang.NoClassDefFoundError: org.springframework.

我在进入httpInvoker后遇到异常,看起来如下:

    INFO: Initializing Spring FrameworkServlet 'httpInvoker' pro 23, 2015
 4:34:04 PM org.apache.catalina.core.ApplicationContext log SEVERE:
 StandardWrapper.Throwable java.lang.NoClassDefFoundError:
 org.springframework.beans.FatalBeanException  at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
   at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
   at
 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
   at
 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
   at
 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
   at
 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
   at
 org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
   at
 org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
   at
 org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
   at
 org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
   at javax.servlet.GenericServlet.init(GenericServlet.java:158)   at
 org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
   at
 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
   at
 org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
   at
 org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
   at
 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
   at
 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)

 pro 23, 2015 4:34:04 PM org.apache.catalina.core.StandardContext
 loadOnStartup SEVERE: Servlet [httpInvoker] in web application
 [/services] threw load() exception java.lang.NoClassDefFoundError:
 org.springframework.beans.FatalBeanException  at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
   at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
   at
 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
   at
 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
   at
 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
   at
 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
   at
 org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
   at
 org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
   at
 org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
   at
 org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
   at javax.servlet.GenericServlet.init(GenericServlet.java:158)   at
 org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
   at
 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
   at
 org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
   at
 org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
   at
 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
   at
 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)
   <!-- <tx:annotation-driven /> -->
    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <!-- define the SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="hr.test.model" />
    </bean>


    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="hr.test.dao.api.mappers" />
    </bean>
经过数小时的研究,我发现spring-db.xml就是问题所在。其中有连接到com.mchange.v2.c3p0.ComboPooledDataSource或EnvironmentProperties的定义。我试着一步一步,逐行注释/取消注释,其中有一部分定义如下:

    INFO: Initializing Spring FrameworkServlet 'httpInvoker' pro 23, 2015
 4:34:04 PM org.apache.catalina.core.ApplicationContext log SEVERE:
 StandardWrapper.Throwable java.lang.NoClassDefFoundError:
 org.springframework.beans.FatalBeanException  at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
   at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
   at
 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
   at
 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
   at
 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
   at
 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
   at
 org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
   at
 org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
   at
 org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
   at
 org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
   at javax.servlet.GenericServlet.init(GenericServlet.java:158)   at
 org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
   at
 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
   at
 org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
   at
 org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
   at
 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
   at
 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)

 pro 23, 2015 4:34:04 PM org.apache.catalina.core.StandardContext
 loadOnStartup SEVERE: Servlet [httpInvoker] in web application
 [/services] threw load() exception java.lang.NoClassDefFoundError:
 org.springframework.beans.FatalBeanException  at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
   at
 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
   at
 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
   at
 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
   at
 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
   at
 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
   at
 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
   at
 org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
   at
 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
   at
 org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
   at
 org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
   at
 org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
   at javax.servlet.GenericServlet.init(GenericServlet.java:158)   at
 org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
   at
 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
   at
 org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
   at
 org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
   at
 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
   at
 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
   at
 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)
   <!-- <tx:annotation-driven /> -->
    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <!-- define the SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="hr.test.model" />
    </bean>


    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="hr.test.dao.api.mappers" />
    </bean>

当我对调用configurer的最后一个bean进行注释时,一切都顺利(毫无例外)

如何停止获取该异常?也许我必须用别的方式写那个豆子?(很抱歉没有给出完整的代码,我只能给出它。)

我正在使用: 月蚀火星 Java 1.8 春季3.1 MyBatis
如果您在下面一行添加注释,则不会显示上面的32位Windows异常

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="hr.test.dao.api.mappers" />
    </bean>

那么我相信您一定错过了项目中的mybatis-spring.jar。请尝试在您的项目中包括以下内容:-

<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.2.3</version>
</dependency>

org.mybatis
mybatis泉
1.2.3

检查地图上的注释。Sheetal Mohan Sharma-您能举例说明可能的错误吗?注释怎么可能是错误的?哪些注释可能导致问题?