@@ -1283,7 +1283,7 @@ public class OrderServiceTest {
1283
1283
production configuration you will define either a set of XML
1284
1284
resource locations or a set of
1285
1285
<interfacename >@Configuration</interfacename > classes that your
1286
- production <interfacename >ApplicationContext</interfacename > will
1286
+ production <interfacename >ApplicationContext</interfacename > will be
1287
1287
loaded from, but you still have the freedom to include or import the
1288
1288
other type of configuration.</para >
1289
1289
</section >
@@ -1362,22 +1362,26 @@ public class ExtendedTest extends BaseTest {
1362
1362
<title >Context configuration with environment profiles</title >
1363
1363
1364
1364
<para >Spring 3.1 introduces first-class support in the framework for
1365
- the notion of environments and profiles (a.k.a., bean definition
1366
- profiles), and integration tests can now be configured to activate
1367
- particular bean definition profiles for various testing scenarios.
1368
- This is achieved by annotating a test class with the new
1369
- @ActiveProfiles annotation and supplying a list of profiles that
1370
- should be activated when loading the ApplicationContext for the
1371
- test.</para >
1365
+ the notion of environments and profiles (a.k.a., <emphasis >bean
1366
+ definition profiles</emphasis >), and integration tests can now be
1367
+ configured to activate particular bean definition profiles for
1368
+ various testing scenarios. This is achieved by annotating a test
1369
+ class with the new <interfacename >@ActiveProfiles</interfacename >
1370
+ annotation and supplying a list of profiles that should be activated
1371
+ when loading the <interfacename >ApplicationContext</interfacename >
1372
+ for the test.</para >
1372
1373
1373
1374
<note >
1374
- <para >@ActiveProfiles may be used with any implementation of the
1375
- new SmartContextLoader SPI, but @ActiveProfiles is not supported
1376
- with implementations of the older ContextLoader SPI.</para >
1375
+ <para ><interfacename >@ActiveProfiles</interfacename > may be used
1376
+ with any implementation of the new
1377
+ <interfacename >SmartContextLoader</interfacename > SPI, but
1378
+ <interfacename >@ActiveProfiles</interfacename > is not supported
1379
+ with implementations of the older
1380
+ <interfacename >ContextLoader</interfacename > SPI.</para >
1377
1381
</note >
1378
1382
1379
1383
<para >Let's take a look at some examples with XML configuration and
1380
- @Configuration classes.</para >
1384
+ < interfacename > @Configuration</ interfacename > classes.</para >
1381
1385
1382
1386
<programlisting language =" xml" >< !-- app-config.xml -->
1383
1387
< beans xmlns="http://www.springframework.org/schema/beans"
@@ -1433,25 +1437,33 @@ public class TransferServiceTest {
1433
1437
}
1434
1438
}</programlisting >
1435
1439
1436
- <para >When TransferServiceTest is run, its ApplicationContext will
1437
- be loaded from the app-config.xml configuration file in the root of
1438
- the classpath. If you inspect app-config.xml you'll notice that the
1439
- accountRepository bean has a dependency on a dataSource bean;
1440
- however, dataSource is not defined as a top-level bean. Instead,
1441
- dataSource is defined twice: once in the production profile and once
1442
- in the dev profile.</para >
1443
-
1444
- <para >By annotating TransferServiceTest with @ActiveProfiles("dev")
1445
- we instruct the Spring TestContext Framework to load the
1446
- ApplicationContext with the active profiles set to {"dev"}. As a
1447
- result, an embedded database will be created, and the
1448
- accountRepository bean will be wired with a reference to the
1449
- development DataSource. And that's likely what we want in an
1450
- integration test.</para >
1440
+ <para >When <classname >TransferServiceTest</classname > is run, its
1441
+ <interfacename >ApplicationContext</interfacename > will be loaded
1442
+ from the <filename >app-config.xml</filename > configuration file in
1443
+ the root of the classpath. If you inspect
1444
+ <filename >app-config.xml</filename > you'll notice that the
1445
+ <varname >accountRepository</varname > bean has a dependency on a
1446
+ <varname >dataSource</varname > bean; however,
1447
+ <varname >dataSource</varname > is not defined as a top-level bean.
1448
+ Instead, <varname >dataSource</varname > is defined twice: once in the
1449
+ <emphasis >production</emphasis > profile and once in the
1450
+ <emphasis >dev</emphasis > profile.</para >
1451
+
1452
+ <para >By annotating <classname >TransferServiceTest</classname > with
1453
+ <interfacename >@ActiveProfiles("dev")</interfacename > we instruct
1454
+ the Spring TestContext Framework to load the
1455
+ <interfacename >ApplicationContext</interfacename > with the active
1456
+ profiles set to <literal >{"dev"}</literal >. As a result, an embedded
1457
+ database will be created, and the
1458
+ <varname >accountRepository</varname > bean will be wired with a
1459
+ reference to the development
1460
+ <interfacename >DataSource</interfacename >. And that's likely what we
1461
+ want in an integration test.</para >
1451
1462
1452
1463
<para >The following code listings demonstrate how to implement the
1453
- same configuration and integration test but using @Configuration
1454
- classes instead of XML.</para >
1464
+ same configuration and integration test but using
1465
+ <interfacename >@Configuration</interfacename > classes instead of
1466
+ XML.</para >
1455
1467
1456
1468
<programlisting language =" java" >@Configuration
1457
1469
@Profile("dev")
@@ -1510,30 +1522,35 @@ public class TransferServiceTest {
1510
1522
}</programlisting >
1511
1523
1512
1524
<para >In this variation, we have split the XML configuration into
1513
- three independent @Configuration classes:</para >
1525
+ three independent <interfacename >@Configuration</interfacename >
1526
+ classes:</para >
1514
1527
1515
1528
<itemizedlist >
1516
1529
<listitem >
1517
- <para >TransferServiceConfig: acquires a dataSource via
1518
- dependency injection using @Autowired</para >
1530
+ <para ><classname >TransferServiceConfig</classname >: acquires a
1531
+ <varname >dataSource</varname > via dependency injection using
1532
+ <interfacename >@Autowired</interfacename ></para >
1519
1533
</listitem >
1520
1534
1521
1535
<listitem >
1522
- <para >StandaloneDataConfig: defines a dataSource for an embedded
1523
- database suitable for developer tests</para >
1536
+ <para ><classname >StandaloneDataConfig</classname >: defines a
1537
+ <varname >dataSource</varname > for an embedded database suitable
1538
+ for developer tests</para >
1524
1539
</listitem >
1525
1540
1526
1541
<listitem >
1527
- <para >JndiDataConfig: defines a dataSource that is retrieved
1528
- from JNDI in a production environment</para >
1542
+ <para ><classname >JndiDataConfig</classname >: defines a
1543
+ <varname >dataSource</varname > that is retrieved from JNDI in a
1544
+ production environment</para >
1529
1545
</listitem >
1530
1546
</itemizedlist >
1531
1547
1532
1548
<para >As with the XML-based configuration example, we still annotate
1533
- TransferServiceTest with @ActiveProfiles("dev"), but this time we
1534
- specify all three configuration classes via the
1535
- @ContextConfiguration annotation. The body of the test class itself
1536
- remains completely unchanged.</para >
1549
+ <classname >TransferServiceTest</classname > with
1550
+ <interfacename >@ActiveProfiles("dev")</interfacename >, but this time
1551
+ we specify all three configuration classes via the
1552
+ <interfacename >@ContextConfiguration </interfacename >annotation. The
1553
+ body of the test class itself remains completely unchanged.</para >
1537
1554
</section >
1538
1555
1539
1556
<section id =" testcontext-ctx-management-caching" >
0 commit comments