控制台错误描述
控制台提示说productService没有定义,我查看了代码的位置
在测试类里找到了productService:
ProductService productService=(ProductService) ctx.getBean("productService");
这段代码又是去找对应的bean的,所以确定问题应该在spring的配置文件中:
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
<bean id="ProductDao" class="com.spm.dao.ProductDao">
<property name="sqlSession" ref="sqlSession"/>
</bean>
<bean id="ProductService" class="com.spm.service.ProductServiceImpl">
<property name="productDao" ref="ProductDao"/>
</bean>
发现问题就出在bean的id上,因为两个名字大小写不一样,导致无法找到对应的类,将两个名字的的大小写改成相同即可。