【问题标题】:WickeTester - IllegalStateException: No CDI context bound to applicationWickeTester - IllegalStateException:没有 CDI 上下文绑定到应用程序
【发布时间】:2023-03-14 03:35:01
【问题描述】:

我有 Wicket Form 和 ProjectNameValidator 类:

@Inject
ProjectDao dao;

 public ProjectNameValidator() {       
    CdiContainer.get().getNonContextualManager().inject(this);
}

这里的注入是因为@Inject注解只在Wicket组件或者Behavior中有效,这里是null,没有CdiContainer.get().getNonContextualManager().inject(this);

但是当我有 WicketTester 时,TestCreateprojectPage:

public class TestCreateProject {

private WicketTester tester;

@Before
public void setUp() throws Exception {
    tester = new WicketTester();
}
@Test
public void createProjectPageRendersSuccessfully() {

    tester.startPage(CreateProject.class);

    tester.assertRenderedPage(CreateProject.class);

} }

我在此行的 ProjectNameValidator 中的 CreateProject.java 中的表单上遇到异常:

CdiContainer.get().getNonContextualManager().inject(this);

IllegalStateException:没有 DCI 上下文绑定到应用程序。

【问题讨论】:

    标签: wicket cdi validation illegalstateexception wicket-tester


    【解决方案1】:

    您的应用程序中有一个未在测试范围内初始化的单例 CdiContainer。所以 CdiContainer.get() 真的是空的。了解如何初始化 CdiContainer 测试上下文,这取决于您的实现,并将其添加到测试 setUp()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-13
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多