SSM中利用MockMvc测试controller出现的几个问题

本文主要讨论了在SSM框架下,使用MockMvc进行controller测试时遇到的两个问题:1) 由于不需要视图解析,注释掉InternalResourceViewResolver解决了bean创建错误;2) 调整MockMvcRequestBuilders.post()中的URL,从"localhost:8080/location/one.json"更改为"http://127.0.0.1:8080/location/one.json",确保了数据库操作的成功。作者作为初学者,期待与读者交流。
摘要由CSDN通过智能技术生成

SSM中利用MockMvc测试controller出现的几个问题

  1. Error creating bean with name ‘locationServiceImpl’
    具体见以下log
十月 21, 2018 10:58:26 上午 org.springframework.web.context.support.GenericWebApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'locationServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ssm.zsc.first.dao.LocationMapper ssm.zsc.first.service.impl.LocationServiceImpl.locationMapper; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframe.web.servlet.view.InternalResourceViewResolver] for bean with name 'org.springframe.web.servlet.view.InternalResourceViewResolver#0' defined in class path resource [spring-web.xml]; nested exception is java.lang.ClassNotFoundException: org.springframe.web.servlet.view.InternalResourceViewResolver
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
	at 

这里仅截取了一部分。

controller部分代码:

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值