Running my my Test class
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:eq-mo-dcc-context-block.xml"})
public class SpringTest {
@Autowired
private DateUtils dateManager;
@Autowired
private RegionFilter filter;
@Autowired
private ApplicationContext appContext;
@Test
public void test_This()
{
Object obj = appContext.getBean("BlockTransformer");
BlockTransformer Trans = (BlockTransformer) obj;
}
All very early stages however the problem that arises the configuration file accesses beans from other Maven modules/Projects. However I have all the xml under src/test/resources, so it can pick up the xml. However the when trying to pick up the class files I get:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [dcc.mdp.DefaultMessageListener] for bean with name 'BlockMessageListener' defined in class path resource [eq-mo-dcc-context-block.xml]; nested exception is java.lang.ClassNotFoundException: dcc.mdp.DefaultMessageListener
This class resides in a sibling maven module, yet cannot be picked up from the test class. How can the class be made aware of classes from other modules other than it’s own?
A Maven module doesn’t automatically “know” anything about other modules under the same parent project, so the sibling module containing the classes you want needs to be listed as a dependency in the module containing your test class.