简体   繁体   中英

Spring error in Cucumber java.lang.IllegalAccessError: tried to access class

I have a cucumber test that is throwing me an illegal access error when I try to fetch a bean. I haven't been able to figure out why this isn't okay.

@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

The solution is to add

@ContextConfiguration(classes = AppInjector.class)

to the top of the class, and then use @Inject to pull in the dependency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM