Hi!
Yes I searched the forum, I used Google, but I'm out of ideas and keywords to search with now.
Problem: I have a new Project with Spring 3.1M2 and I want to run JUnit tests like the following:
But, as you may guess, it does not work.Code:@RunWith(SpringJUnit4ClassRunner.class) @ComponentScan(basePackages = {"de.my.packages"}) public abstract class AbstractAmqpTests { ... }
I have no XML Configs in my Project, just Config-Classes like those:
The application works with a Main-Application, which works:Code:@Configuration public class DataSourceConfig { @Bean public DataSource dataSource() throws ClassNotFoundException { ... }
I cannot find an example how to run the tests with a Component Scan, execpt of the following solution, but there have to be a better one instead of list every Config-Class:Code:public class Main { public static void main(String[] args) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext("de.my.packages"); System.out.println("Ready."); }
The Exception on starting the test:Code:@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {DataSourceConfig.class, JobDetailConfig.class, RabbitServerConfig.class, SchedulerFactoryConfig.class, TriggerConfig.class, MessageHandlerConfig.class, QuartzSchemaHelper.class, CalendarHandler.class, HostHandler.class, ServiceHandler.class, ConfigMessageHandler.class})
Btw: When I follow the hint to add a @ContextConfiguration then he tries to load a XML-File, which I not have. I even tried to give him such a XML with just a <context:component-scan /> in it, but that does not work either.Code:java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:181) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) ... Caused by: java.lang.IllegalArgumentException: Can not load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration. at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:121)



Reply With Quote
. But it probably wasn't that hard to fix my mistake
