文件的目录结构如下
报错截图如下:
这个时候的思考:
1.bean有没有注入 √
2.junit单元测试,看service调用dao层能否查询成功 √
3.所以问题出在了spring上,可能是web.xml没有配置扫描spring.xml文件,只扫描了spring-mvc文件。
解决:
在原来的web.xml基础上添加了
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
后面运行成功截图