ssm项目Tomcat启动报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LoginDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'LoginMapper' is defined
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5017)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5531)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
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:748)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'LoginMapper' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1159)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:282)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:446)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:420)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:545)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305)
... 22 more
这是dao实现类


@Repository("LoginDao")
public class LoginDaoImpl implements LoginDao {

    @Resource(name = "LoginMapper")
    private LoginMapper LoginMapper;

    public LoginMapper getLoginMapper() {
        return LoginMapper;
    }

    public void setLoginMapper(LoginMapper loginMapper) {
        LoginMapper = loginMapper;
    }

这是service实现类

 @Service("LoginService")
public class LoginServiceImpl implements LoginService {

    @Resource
     private LoginDao LoginDao;

配置文件
<?xml version="1.0" encoding="UTF-8"?>
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- 引入我们的database.properties,hibernate.properties文件 -->
<bean id="property" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="locations">
         <list>
            <value>classpath:database.properties</value><!-- classpath代表类路径,如src下面的文件 -->

         </list>

     </property>
</bean> 

<!-- 定义使用C3P0连接池的数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <!-- 指定连接数据库的JDBC驱动 -->
    <property name="driverClass">
        <value>${mysql.driver_class}</value>
     </property>
    <!-- 连接数据库所用的URL -->
    <property name="jdbcUrl">
        <value>${mysql.connection.url}</value>
    </property>
    <!-- 连接数据库的用户名 -->
    <property name="user">
        <value>${mysql.connection.username}</value>
    </property>
    <!-- 连接数据库的密码 -->
    <property name="password">
        <value>${mysql.connection.password}</value>
    </property>
    <!-- 设置数据库连接池的最大连接数 -->
    <property name="maxPoolSize">
        <value>30</value>
    </property>
    <!-- 设置数据库连接池的最小连接数 -->
    <property name="minPoolSize">
        <value>2</value>
    </property>
    <!-- 设置数据库连接池的初始化连接数 -->
    <property name="initialPoolSize">
        <value>2</value>
    </property>
    <!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 -->
    <property name="maxIdleTime">
        <value>10</value>
    </property>
</bean>

 <!-- 启用自动扫描 -->
<context:component-scan base-package="com.kachi.*">
  <context:exclude-filter type="annotation" 
            expression="org.springframework.stereotype.Controller" /><!-- 排除注解为controller的类型 -->
</context:component-scan>


<!-- 配置SqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:mybatis.xml"/>
    <!-- mapper和resultmap配置路径 -->
    <property name="mapperLocations">
        <list>          
            <value>classpath:entity/config/*.xml</value>
        </list>
    </property>
</bean> 


<!-- 自动扫描mapper接口,注入sqlsessionfactory -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.kachi.mapper"/>
</bean>


<!-- 开启 mybatis事务-->
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager"  proxy-target-class="true"/>

springmvc配置文件
<?xml version="1.0" encoding="UTF-8"?>

<!--  <mvc:annotation-driven/>该注解可以代替下面的两个注解 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >  
<property name="messageConverters">   
     <list>   
         <bean class = "org.springframework.http.converter.StringHttpMessageConverter">   
            <property name = "supportedMediaTypes">
                  <list>
                      <value>text/html;charset=UTF-8</value>   
                 </list>   
            </property>   
         </bean>   
     </list>   
</property>  
</bean>  
<!-- 注解探测器 -->
<context:component-scan base-package="com.kachi.controller"/>


<!-- 静态资源访问 -->
 <mvc:resources location="/css/" mapping="/css/**"/>  
 <mvc:resources location="/js/" mapping="/js/**"/> 
 <mvc:resources location="/font/" mapping="/font/**"/>   
 <mvc:resources location="/images/" mapping="/images/**"/>   

<!--  annotation默认的方法映射适配器 ,视图解析器,类似于action-->
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /><!-- 寻找类 -->

<bean id="handlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /><!-- 根据url找方法 -->

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

2个回答

应该是MyBatis的配置文件有错,LoginMapper可能没有配置

你的loginmapper呢,怎么没有截图过来

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐