有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java中的Spring错误。lang.IllegalAccessError:试图访问类

我有一个cucumber测试,当我试图获取一个bean时,它会抛出一个非法访问错误。我一直不明白为什么这不好

@Given('^test$')
public void myTest(){
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AppInjector.class);
    MyBean bean = ctx.getBean(MyBean.class)
}

java.lang.IllegalAccessError: tried to access class MyBean from StepDef

共 (1) 个答案

  1. # 1 楼答案

    解决办法是增加

    @ContextConfiguration(classes = AppInjector.class)
    

    到类的顶部,然后使用@Inject拉入依赖项