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>