ApplicationContextAware only works for Spring Beans. You can use @Configurable , but this requires AspectJ.
Here is a simple hack that should work: add a static member to your listener class and enter it through a non-static setter.
public class MyMethodListener implements IInvokedMethodListener { private static MyBean myBean; @Autowired public void setMyBean(MyBean myBean) { MyMethodListener.myBean = myBean; } }
Include the bean of the required type in the application context.
The listener created with TestNG will not be the same instance as the Spring context, but it will have a static member set, provided that the context creation is complete before TestNG creates the listener instance.
source share