What is the Difference between @SpringApplicationConfiguration
and @ContextConfiguration
with respect to JUnit test cases?
@ContextConfiguration
is an annotation from the Spring Test Framework, which is suitable for every Spring application, @SpringApplicationConfiguration
is from Spring Boot and is actually a composite annotation, which includes ContextConfiguration
with the custom SpringApplicationContextLoader
as loader.
@ContextConfiguration
and @SpringApplicationConfiguration
both are doing same. Both load and configure an ApplicationContext for integration tests. But @ContextConfiguration
has some lacking for support.
Prior to Spring 3.1
, only path-based resource locations (typically XML configuration files) were supported. As of Spring 3.1, context loaders may choose to support either path-based or class-based resources.
As of Spring 4.0.4, context loaders may choose to support path-based and class-based resources simultaneously. Consequently @ContextConfiguration
can be used to declare either path-based resource locations (via the locations() or value() attribute) or annotated classes (via the classes() attribute).
Note, however, that most implementations of SmartContextLoader only support a single resource type. As of Spring 4.1, path-based resource locations may be either XML configuration files or Groovy scripts (if Groovy is on the classpath). Of course, third-party frameworks may choose to support additional types of path-based resources.
@SpringApplicationConfiguration
is similar to the standard @ContextConfiguration
but uses Spring Boot's SpringApplicationContextLoader.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With