Forsaken12345 2018-02-07 02:25 采纳率: 100%
浏览 1507
已采纳

SSM整合,测试时提示NoSuchBeanDefinitionException

spring配置文件:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 引入properties -->
    <context:property-placeholder location="mysql.properties"/>
    <!-- 配置数据库连接池 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${mysql.driver}"/>
        <property name="jdbcUrl" value="${mysql.url}"/>
        <property name="user" value="${mysql.username}"/>
        <property name="password" value="${mysql.password}"/>
    </bean>
    <!-- 配置mybatis的SqlSession的工厂:SqlSessionFactoryBean dataSource:注入数据源 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据源 -->
        <property name="dataSource" ref="dataSource"></property>
        <!-- 指定要使用到mybatis配置文件 -->
        <property name="configLocation" value="classpath:mybatis_config.xml"/>
        <!-- 用于配置mapper映射xml -->
        <property name="mapperLocations" value="classpath*:cn.gzx/mapper/*.xml"/>
    </bean>
    <!-- 创建数据映射器 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.gzx.dao"/>
    </bean>
    <!-- 对数据源进行事物管理 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

</beans>

web.xml配置文件:

 <!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
   <!-- spring配置 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath*:spring/applicationContext.xml
    </param-value>
  </context-param>
   <!-- 配置spring上下文监听器 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextCleanupListener</listener-class>
  </listener>


</web-app>

目录:
图片说明
测试文件:
图片说明
错误:
图片说明

这里为什么bean注入失败,小白,求解

  • 写回答

11条回答

  • yrunow 2018-02-07 06:12
    关注

    意思就是找不到AdminDao这个bean,而且你这句话

        <property name="mapperLocations" value="classpath*:cn.gzx/mapper/*.xml"/>这个地方我没记错应该写作classpath:cn/gzx/mapper/*.xml,
                如果要这样写的话映射文件名要写作和dao接口名一样,就是说你叫adminDao.java就得把mapper写作adminDao.xml
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)