I have a spring boot application with a main class as shown below:
@SpringBootApplication public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }
Now I want to test my services and create a base test class:
@SpringApplicationConfiguration(Application.class) public abstract class TestBase { }
When I run my test, I get an exception:
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:115) at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:117) at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
Then I change the base test class using ContextConfiguration
@ContextConfiguration(classes = Application.class) public abstract class TestBase { }
This time I get a DataSource initialization error. I wonder why this happens in the first case and why in the second case it does not load my .properties applications, where I configured the data source.
Thanks!
source share