Circular view path [...]: would dispatch back to the current handler
来源:互联网 发布:制作linux安装u盘 编辑:程序博客网 时间:2024/06/14 12:30
在对mvc进行测试时,即便指定了配置文件中的视图解析依然没有作用,测试时会报异常:
javax.servlet.ServletException: Circular view path [list]: would dispatch back to the current handler URL [/list] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
网上提到此问题的有:
http://stackoverflow.com/questions/18813615/how-to-avoid-the-circular-view-path-exception-with-spring-mvc-test
以及
https://myshittycode.com/2014/01/17/mockmvc-circular-view-path-view-would-dispatch-back-to-the-current-handler-url-view-again/
摘录答案中的话,When you don’t declare a ViewResolver, Spring registers a default InternalResourceViewResolver which creates instances of JstlView for rendering the View.
当你没有声明ViewResolver时,spring会给你注册一个默认的ViewResolver,其是JstlView的实例。它通过RequestDispatcher寻找资源(视图),不过这个资源也可能是Servlet,也就是说,Controller中方法返回字符串(视图名),也可能会解析成Servlet。当你的请求路径与视图名相同时,就会发生死循环。
这就是异常提示的信息。不过我依然不明白为什么配置了视图解析还是不行,依据网上的方法可以解决问题,那就是在测试类中再配置一遍视图
@ContextConfiguration(classes = {com.wthfeng.hello.config.WebConfig.class}) //加载配置文件@WebAppConfiguration //测试时启动一个web服务@RunWith(SpringJUnit4ClassRunner.class) //表明用spring test进行测试public class TestJavaConfig { private MockMvc mockMvc; @InjectMocks private StudentController studentController; @Mock private StudentService studentService; @Before public void setUp(){ MockitoAnnotations.initMocks(this); InternalResourceViewResolver resolver = new InternalResourceViewResolver(); //配置视图解析器 resolver.setPrefix("/WEB_INF/views"); resolver.setSuffix(".jsp"); mockMvc = MockMvcBuilders.standaloneSetup(studentController).setViewResolvers(resolver).build(); } @Test public void testList()throws Exception{ mockMvc.perform(get("/list")).andExpect(view().name("list")).andExpect(model().attributeExists("StudentList")); }}
- Circular view path [...]: would dispatch back to the current handler
- Circular view path [...]: would dispatch back to the current handler
- Circular view path : would dispatch back to the current handler URL again. Check your ViewResolver s
- Circular view path [login3]: would dispatch back to the current handler URL [/Spring_Demo/login3]
- Circular view path [faults]: would dispatch back to the current handler URL [/pulsar/faults] again
- Spring boot 报错:Circular view path [...]: would dispatch back to the current handler
- spring cloud 报[Circular view path [refundbbb]: would dispatch back to the current handler URL [/refu
- 《Springboot极简教程》问题解决:javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL
- javax.servlet.ServletException: Circular view path [list]: would dispatch back to the current handle
- javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handl
- spring boot would dispatch back to the current handler URL [/hello] again. Check your ViewResolver s
- Circular view path
- 今天踩了个大坑,springmvc的Circular view path
- javax.servlet.ServletException: Circular view path......Check your ViewResolver setup!
- spring boot thymeleaf错误之Circular view path [...]
- Software Engineering: A Look Back and A Path to the Future
- Rose出现 “relation from A to B would cause an Invalid circular inheritance"解决方法。
- UML工具Rose出现 “relation from A to B would cause an Invalid circular inheritance"“。
- 阻塞队列实现--生产消费模型
- SQL 之 外连接
- java io系列13之 BufferedOutputStream(缓冲输出流)的认知、源码和示例
- 贪吃蛇微信小程序
- SUMO文档007:高级教程(上)
- Circular view path [...]: would dispatch back to the current handler
- My SQL 联合查询的使用
- 伙伴系统算法详解
- 实验2 Activity和Intent-任务3:理解Task
- 剑指Offer面试题36(Java版):数组中的逆序对
- spring @Transactional 注解
- 排序算法之冒泡排序
- 枚举整数的整数和的所有组合
- Android使用Lambda表达式 - retrolambda插件(优缺点)