栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

基于Spring Boot的测试中的上下文层次结构

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于Spring Boot的测试中的上下文层次结构

更新: 如Peter Davis所述,此问题已在Spring Boot 1.5.0中修复。

这是的限制

@SpringBootTest
。准确移动,这是的限制
SpringBootContextLoader
。您可以通过使用配置父上下文的自定义上下文加载器或
ContextCustomizer
需要在中列出的工厂来解决此问题
spring.factories
。这是后者的粗略示例:

src / test / resources / meta-INF / spring.factories:

org.springframework.test.context.ContextCustomizerFactory=com.alex.demo.ctx.HierarchyContextCustomizerFactory

src / test / java / com / alex / demo / ctx /

HierarchyContextCustomizerFactory.java:

package com.alex.demo.ctx;import java.util.List;import org.springframework.context.ConfigurableApplicationContext;import org.springframework.test.context.ContextConfigurationAttributes;import org.springframework.test.context.ContextCustomizer;import org.springframework.test.context.ContextCustomizerFactory;import org.springframework.test.context.MergedContextConfiguration;public class HierarchyContextCustomizerFactory implements ContextCustomizerFactory {    @Override    public ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) {        return new ContextCustomizer() { @Override public void customizeContext(ConfigurableApplicationContext context,         MergedContextConfiguration mergedConfig) {     if (mergedConfig.getParentApplicationContext() != null) {         context.setParent(mergedConfig.getParentApplicationContext());     } }        };    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/394179.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号