清风浊酒歌年少i 2021-03-07 02:38 采纳率: 0%
浏览 331

为什么整合ssm一致报嵌套异常org.springframework.beans.factory

 

Error creating bean with name 'teacherServiceImpl': Unsatisfied dependency expressed through field 'teacherDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'teacherDao' defined in file [D:\Users\key\IdeaProjects\SSMStruts\target\SSMStruts\WEB-INF\classes\com\wangheng\dao\TeacherDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactoryBean' defined in class path resource [Applicaption.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'ServletContext resource [/TeacherDao.xml]'; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/TeacherDao.xml

翻译:

创建名为“teacherServiceImpl”的bean时出错:通过字段“teacherDao”表示的依赖不满足;嵌套异常是org.springframework.beans.factory。UnsatisfiedDependencyException:创建名为“teacherDao”的bean时出错,该bean定义在文件中[D: Users\key\IdeaProjects\SSMStruts\target\SSMStruts\WEB-INF\classes\com\wangheng\dao\ teacherDao]。通过bean属性'sqlSessionFactory'表示的未满足的依赖关系;嵌套异常是org.springframework.beans.factory。BeanCreationException:创建名称为“sqlSessionFactoryBean”的bean时出错,该bean定义在类路径资源[application . properties]中。: init方法调用失败;嵌套异常是org.springframework.core。NestedIOException: Failed to parse mapping resource: 'ServletContext resource [/TeacherDao.xml]';嵌套异常是java.io。FileNotFoundException: Could not open ServletContext resource [/TeacherDao.xml .

<?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"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       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
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd

">
        <context:component-scan base-package="com.wangheng.*">
<!--            除了这个注释不加入ioc容器其他的注释文件都扫描进ioc容器-->
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        </context:component-scan>
<!--    将数据库链接配置文件导入ioc-->
    <context:property-placeholder  location="jdbc.properties" file-encoding="UTF-8" ignore-resource-not-found="true" ignore-unresolvable="true" local-override="false"/>
        <bean  id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!--            读取链接数据库数据-->
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.username}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="driverClassName" value="${jdbc.driver}"/>
        </bean>

<!--    spring整合Mybatis-->
<!--    将mybatis核心sqlSessionFactoryBean加入ioc容器-->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--        指定Mybatis配置文件文件-->
        <property name="configLocation" value="Mybatis-config.xml"/>
<!--   指定mybatis使用哪个数据库    -->
        <property name="dataSource" ref="dataSource"/>
<!--        指定sql映射文件位置-->
        <property name="mapperLocations" value="TeacherDao.xml"/>
    </bean>
<!--    将dao每一个接口的实现加入到ioc容器中-->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--        指定dao接口所在的包-->
        <property name="basePackage" value="com.wangheng.dao"/>
    </bean>


<!--    定义数据源管理器管理数据源-->
    <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--        使用事务管理器定义事务的管理类型,管理哪个类型的事务,管理的目标对象-->
        <!-- name="dataSource":管理的类型     ref:引用管理哪个数据源   -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>
<!--    使用tx和aop名称空间标签-->
<aop:config>
    <aop:pointcut id="aspect" expression="execution(* com.wangheng.service.*(..))"/>
<!--   advice-ref="":切入点表达式切入事务管理器   pointcut-ref="aspect":切入点表达式-->
    <aop:advisor advice-ref="myTransactionManger" pointcut-ref="aspect"/>
</aop:config>
<!--  transaction-manager="dataSourceTransactionManager":事务管理器管理数据源管理器  -->
    <tx:advice id="myTransactionManger" transaction-manager="dataSourceTransactionManager">
<!--        配置事务属性-->
        <tx:attributes>
<!--            配置切入点表达式具体切入哪些方法-->
            <tx:method name="*" rollback-for="java.lang.Exception"/>
            <tx:method name="get*" read-only="true"/>
<!--            <tx:method name="insertEmp" isolation="READ_UNCOMMITTED"/>-->
        </tx:attributes>
    </tx:advice>

</beans>
  • 写回答

2条回答 默认 最新

  • 关注

    配置有问题啊,注意看报错,提示已经很明确了

    评论

报告相同问题?

悬赏问题

  • ¥15 求修改代码,图书管理系统
  • ¥15 请问有没求偏多标签数据集yeast,reference,recreation,scene,health数据集。
  • ¥15 传感网应用开发单片机实训
  • ¥15 Delphi 关于sAlphaImageList使用问题
  • ¥15 寻找将CAJ格式文档转txt文本的方案
  • ¥20 数电设计提问求帮助,出租车计费器
  • ¥15 shein测试开发会问些啥我是写java的
  • ¥15 关于#单片机#的问题:我有个课程项目设计,我想在STM32F103veTX单片机,M3主控模块上设计一个程序,在Keil uVision5(C语言)上代码该怎么编译?(嫌钱少我可以加钱,急急急)
  • ¥15 opnet仿真网络协议遇到问题
  • ¥15 在安装python的机器学习程序包scikit-learn(1.1版本)时遇到如下问题