I have my Spring app where the application context is loaded properly and working. But when I try to load it in my tests, the application context loaded does not contain any of the beans declared in config files.
@Test
public void testInsertMapitPoint() {
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:*/application-ds-context.xml","classpath:*/application-dao-context.xml" });
System.out.println("Bean Names:");
for (String beanName : context.getBeanDefinitionNames()) {
System.out.println(beanName);
}
}
The displayed test does not show any bean in the context. Any help?
With a pattern like
classpath:*/application-ds-context.xml
// ^ this guy
Spring will load any file that matches that pattern. Any meaning it might not find/load any. In this example, it will look for any file called application-ds-context.xml
that is in any 1st level package.
For example, it will find
/classpath-root
/first
application-ds-context.xml
but it won't find
/classpath-root
application-ds-context.xml
or
/classpath-root
/first
/second
application-ds-context.xml
If that's the behavior you are seeing, your classpath does not contain such a file. Review how you are building your test application.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.