第一个问题:

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



相关文章:

  • 2021-12-07
  • 2022-03-06
  • 2021-04-18
  • 2021-11-01
  • 2021-12-21
  • 2021-08-05
  • 2021-05-11
  • 2021-09-25
猜你喜欢
  • 2021-08-20
  • 2022-12-23
  • 2021-04-20
  • 2021-10-19
  • 2022-01-05
  • 2022-01-03
  • 2021-12-31
相关资源
相似解决方案