I am trying to learn how to use applicationContext. My goal is to exchange real-time file storage using my unit tests. I do not want to do this explicitly, I want to do this with dependency injection.
So, as a simple test, before I get complicated, I'm just trying to get a bean from my applicationContext.xml. From what I read, this should work:
@ContextConfiguration(locations = "/applicationContext.xml")
public class ResultsListTests {
@Resource
CompanyResult resultBean;
@Test
public void shouldAddResults() {
assertEquals(resultBean.getCompanyName(), "Microsoft");
But my Bean result is always zero. Here is my applicationContext.xml which is under WebContent / WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<bean id="resultBean" name="resultBean" class="com.trgr.cobalt.company.domain.CompanyResult">
<property name="companyName">
<value>Microsoft</value>
</property>
</bean>
</beans>
So why is my Bean result always null? What did I do wrong?
source
share