zoukankan      html  css  js  c++  java
  • Spring-boot非Mock测试MVC,调试启动tomcat容器

    平常我们在使用spring-boot去debug一个web应用时,通常会使用MockMvc。

    如下配置:

    @RunWith(value = SpringRunner.class)
    @SpringBootTest(classes = xxxx.class)

    但是这样并不会真的打开嵌入式servlet容器

    spring不愧是个强大的框架,心想着它肯定有配置真正打开容器的地方,然后带着想法去看源码,果然发现了可配置的东西~

    这样配置就好了:

    @RunWith(value = SpringRunner.class)
    @SpringBootTest(
        webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
        classes = xxxx.class
    )

    在默认情况下,SpringRunner给SpringApplication这个类设置了applicationContextClass(GenericWebApplicatoinContext),这个时候SpringApplication将不会去初始化applicationContextClass为AnnotationConfigEmbeddedWebApplicationContext

  • 相关阅读:
    MyCat清单
    Nginx整合Tomcat
    Nginx安装与配置
    Spring清单
    Shiro清单
    Dubbo清单
    MyBatis清单
    查询数据库的编码
    myBatis
    面试
  • 原文地址:https://www.cnblogs.com/lanhj/p/6159735.html
Copyright © 2011-2022 走看看