I´ve using JUnit but some tests have some issues, these tests have @Autowired annotation inside the Spring beans and when i reference them the beans that are @Autowired were always NULL.
Here is the example code:
public class Test {
protected ApplicationContext ac;
@Before
public void setUp() {
ac = new FileSystemXmlApplicationContext("classpath:config/applicationContext.xml"
"classpath:config/test-datasources.xml");
}
@Test
public void testRun() throws Exception {
IManager manager = (IManager)this.ac.getBean("manager");
manager.doSomething();
}
}
@Service
public class Manager implements IManager {
public boolean doSomething() throws Exception {
ParametersJCSCache parametersJCSCache = new ParametersJCSCache();
String paramValue = parametersJCSCache.getParameter("XPTO");
...
}
}
public class ParametersJCSCache extends SpringBeanAutowiringSupport {
@Autowired
private IParameterManager parameterManager; //THIS IS NULL
}
When invoking the Manager object the Spring generates the proxy but when accessing the @Autowired parameterManager the object is null, and with this issue i can´t test this method.
Any idea what is causing this? Why does the object not get injected? It works well in the context of a web application, but in the test context is always NULL.