SSM整合时出现的两个问题

第一个问题:

SSM框架整合中:出现错误:NoSuchBean(service层)

报错如下:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.tmj.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}



最后找到原因:没有整合Spring和SpringMVC,应在Web.xml中整合Spring:如下图:

SSM整合时出现的两个问题_第1张图片

        代码也贴在这了:


 
contextConfigLocation
classpath:applicationContext-*.xml


org.springframework.web.context.ContextLoaderListener
 



第二个问题:

SSM整合时,报500,如下:

SSM整合时出现的两个问题_第2张图片

严重: Servlet.service() for servlet [SpringMVC] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.tmj.mapper.UserMapper.getAll] with root cause

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.tmj.mapper.UserMapper.getAll


最后发现原因是:Spring没有绑定好Mapper.xml文件;

解决办法:

把Mapper.xml放在classpath路径下,然后在Spring-Mybatis配置文件配置sqlsessionFactory的时候添了这一句:

 

SSM整合时出现的两个问题_第3张图片



你可能感兴趣的:(SSM整合时出现的两个问题)