|
437 | 437 | <emphasis>either</emphasis> the application context resource
|
438 | 438 | <literal>locations</literal> <emphasis>or</emphasis> the
|
439 | 439 | <interfacename>@Configuration</interfacename>
|
440 |
| - <varname>classes</varname> to load as well as the |
| 440 | + <varname>classes</varname> (but not both) to load as well as the |
441 | 441 | <interfacename>ContextLoader</interfacename> strategy to use for
|
442 | 442 | loading the context. Note, however, that you typically do not need
|
443 | 443 | to explicitly configure the loader since the default loader
|
@@ -1253,6 +1253,40 @@ public class OrderServiceTest {
|
1253 | 1253 | }</programlisting>
|
1254 | 1254 | </section>
|
1255 | 1255 |
|
| 1256 | + <section id="testcontext-ctx-management-mixed-config"> |
| 1257 | + <title>Mixing XML resources and @Configuration classes</title> |
| 1258 | + |
| 1259 | + <para>It may sometimes be desirable to mix XML resources and |
| 1260 | + <interfacename>@Configuration</interfacename> classes to configure |
| 1261 | + an <interfacename>ApplicationContext</interfacename> for your tests. |
| 1262 | + For example, if you use XML configuration in production, you may |
| 1263 | + decide that you want to use |
| 1264 | + <interfacename>@Configuration</interfacename> classes to configure |
| 1265 | + specific Spring-managed components for your tests, or vice versa. As |
| 1266 | + mentioned in <xref |
| 1267 | + linkend="integration-testing-annotations-spring" /> the TestContext |
| 1268 | + framework does not allow you to declare <emphasis>both</emphasis> |
| 1269 | + via <interfacename>@ContextConfiguration</interfacename>, but this |
| 1270 | + does not mean that you cannot use both. If you want to use XML |
| 1271 | + <emphasis role="bold">and</emphasis> |
| 1272 | + <interfacename>@Configuration</interfacename> classes to configure |
| 1273 | + your tests, you will have to pick one as the <emphasis>entry |
| 1274 | + point</emphasis>, and that one will have to include or import the |
| 1275 | + other. For example, in XML you can include |
| 1276 | + <interfacename>@Configuration</interfacename> classes in component |
| 1277 | + scanning or define them as normal Spring beans; whereas, in a |
| 1278 | + <interfacename>@Configuration</interfacename> class you can use |
| 1279 | + <interfacename>@ImportResource</interfacename> to import XML |
| 1280 | + configuration files. Note that this behavior is semantically |
| 1281 | + equivalent to how you configure your application in production: in |
| 1282 | + production configuration you will define either a set of XML |
| 1283 | + resource locations or a set of |
| 1284 | + <interfacename>@Configuration</interfacename> classes that your |
| 1285 | + production <interfacename>ApplicationContext</interfacename> will |
| 1286 | + load, but you still have the freedom to include or import the other |
| 1287 | + type of configuration.</para> |
| 1288 | + </section> |
| 1289 | + |
1256 | 1290 | <section id="testcontext-ctx-management-inheritance">
|
1257 | 1291 | <title>Context configuration inheritance</title>
|
1258 | 1292 |
|
|
0 commit comments