Cannot resolve reference to bean ‘sqlSessionFactory‘ while setting constructor argument; nested exce

1.报错信息

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeMapper' 
defined in file [D:\eclipse\eclipse_new_new\struct\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ssmTest1_20210301
\WEB-INF\classes\com\feng\dao\EmployeeMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionTemplate'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSession' defined in 
class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting constructor argument;
 nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sqlSessionFactory' available

2.报错原因:
spring配置文件中出错了
下面一个里面ref引用路径错误了,上面里面配置的id=“sqlSessionFactoryBean” ,下面的ref=“sqlSessionFactoryBean” 才对,但是写成了ref=“sqlSessionFactory”

	
	<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource">property>
		<property name="configLocation" value="classpath:mybatis-config.xml">property>
		<property name="mapperLocations" value="classpath:mybatis/mapper/*.xml">property>
	bean>
	
	<mybatis-spring:scan base-package="com.feng.dao"/>
	

	<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory">constructor-arg>
		<constructor-arg name="executorType" value="BATCH">constructor-arg>
	bean> 

3.解决方法
根据第二点就知道怎么改了

你可能感兴趣的:(mybatis,mybatis,spring,eclipse)