diff --git a/src/main/resources/spring/business-config.xml b/src/main/resources/spring/business-config.xml index 731bd1c25ceddac4e60ebbbdf1dad1b30a23f8dd..5cc8bd2a2d312b9d2018fbb9a658e12444266826 100644 --- a/src/main/resources/spring/business-config.xml +++ b/src/main/resources/spring/business-config.xml @@ -25,8 +25,14 @@ <!-- enables scanning for @Transactional annotations --> <tx:annotation-driven /> - - <beans profile="jpa,spring-data-jpa"> + + <!-- ================== 3 Profiles to choose from =================== + - default (uses JPA) + - jdbc (uses Spring" JdbcTemplate) + - spring-data-jpa + =============================================================================--> + + <beans profile="default,spring-data-jpa"> <!-- JPA EntityManagerFactory --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource"> @@ -69,8 +75,9 @@ <context:component-scan base-package="org.springframework.samples.petclinic.repository.jdbc"/> </beans> - <beans profile="jpa"> + <beans profile="default"> <!-- + Loads JPA beans Will automatically be transactional due to @Transactional. EntityManager will be auto-injected due to @PersistenceContext. PersistenceExceptions will be auto-translated due to @Repository. diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 000f6244c1a85c35fb336479bf98d408062f45f8..a19348eecb30d7df6d719d48e81681afc9b2f3b4 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -8,15 +8,20 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" <display-name>Spring PetClinic</display-name> <description>Spring PetClinic sample application</description> - <context-param> + <!-- Default profile is "jpa" (see business-config.xml for more details). + When using Spring JDBC, uncomment the following: --> + <!-- <context-param> <param-name>spring.profiles.active</param-name> <param-value>jdbc</param-value> - <!-- Available profiles: - <param-value>jdbc</param-value> - <param-value>jpa</param-value> (in the case of plain JPA) - <param-value>spring-data-jpa</param-value> (in the case of Spring Data JPA) - --> + </context-param> --> + + <!-- When using Spring Data JPA, uncomment the following: --> + <!-- + <context-param> + <param-name>spring.profiles.active</param-name> + <param-value>spring-data-jpa</param-value> </context-param> + --> <!-- - Location of the XML file that defines the root application context. diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java index e024f21fd09c37fb8e838e114872b8877fc41971..2512372a4f4d9dcd6d844a909c9b64955d1978a0 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java @@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.service; import org.junit.runner.RunWith; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -17,7 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) @RunWith(SpringJUnit4ClassRunner.class) -@ActiveProfiles("jpa") +// No active profile specificied because JPA uses the "default" profile public class ClinicServiceJpaTests extends AbstractClinicServiceTests { } \ No newline at end of file