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整合时出现的两个问题

        代码也贴在这了:

<!-- 加载spring容器 -->
  <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 



第二个问题:

SSM整合时,报500,如下:

SSM整合时出现的两个问题

严重: 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的时候添了这一句:

<property name="mapperLocations" value="classpath:mapper/*.xml"></property> 

SSM整合时出现的两个问题