2017-05-08 95 views
0

在我的java春天mvc中,我试图用黄瓜和硒进行测试。 我有以下类,它负责调用驱动程序。硒:依赖注射不起作用

@Service 
public class BaseUtil { 

    public void caller(){ 
     System.out.println("Caller Firefox driver here!!!!!!!"); 
    } 

} 

,然后在步骤定义类我要去,使依赖注入步骤:

@Component 
public class StepDefenitions{ 

    @Autowired 
    BaseUtil base; 


    @Given("^I want to register into the main forum$") 
    public void i_want_to_register_into_the_main_forum() throws Throwable { 
     base.caller(); 

    }} 

但它与

java.lang.NullPointerException 
     at com.exercise.StepDefenitions.i_want_to_register_into_the_main_forum(StepDefenitions.java:26) 

那么,为什么@Autowierd不抱怨在这里工作?

+0

“StepDefenitions”是一个弹簧管理bean吗? – Jens

+0

延斯是对的。您是否在StepDefinitions类中拥有@Component或@ Service类 – pvpkiran

+0

否它包含黄瓜功能文件的步骤。但是,我不知道如果我回答你的问题@Jens – Salman

回答

0

StepDefenitions需要成为托管bean才能注入其依赖关系。

使用@Component或@Service对其进行注释。

+0

我用我们的解决方案更新了我的问题。我试过'@ Service'和'@ Component'两个都失败了 – Salman

+0

您是使用@Configuration还是xml来定义bean? – Raphael

+0

我没有他们现在。所以,我想,我可以拥有他们两个 – Salman