I need to do a @BeforeClass
method in junit but inject values using Spring so can\'t switch private
variables to static
. I am trying to do
It's not the cleanest, but it works:
public class MyTestListener extends AbstractTestExecutionListener {
@Value("${my.value}")
private String myValue;
@Autowired
private MyBean myBean;
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
testContext.getApplicationContext()
.getAutowireCapableBeanFactory()
.autowireBean(this);
}
}