diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java index 14d3c8eea1dd1d7edbe0f1cded4ee4f8510d8108..58c8614eacfc6aa3474d4df4310b73e8b2a64de3 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java @@ -61,7 +61,6 @@ public class JdbcVetRepositoryImpl implements VetRepository { * @see org.springframework.samples.petclinic.model.service.ClinicService#findVets() */ @Override - @Cacheable(value = "vets") public Collection<Vet> findAll() throws DataAccessException { List<Vet> vets = new ArrayList<Vet>(); // Retrieve the list of all vets. diff --git a/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java b/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java index df628d3b9169a5843af2f068d7d2ed6a12476cc2..6db1fc29665368c0522f756472d52fa4005a92c3 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java @@ -18,6 +18,7 @@ package org.springframework.samples.petclinic.service; import java.util.Collection; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.dao.DataAccessException; import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Pet; @@ -98,6 +99,7 @@ public class ClinicServiceImpl implements ClinicService { @Override @Transactional(readOnly = true) + @Cacheable(value = "vets") public Collection<Vet> findVets() throws DataAccessException { return vetRepository.findAll(); } diff --git a/src/main/resources/spring/business-config.xml b/src/main/resources/spring/business-config.xml index 9ea5c17640164362cf1ccc42ddbf47b58e933987..84b50037344a1026bc7c0a6efdbf5dbf039debca 100644 --- a/src/main/resources/spring/business-config.xml +++ b/src/main/resources/spring/business-config.xml @@ -1,21 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Application context definition for PetClinic on JPA. + Repository and Service layers --> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:p="http://www.springframework.org/schema/p" - xmlns:context="http://www.springframework.org/schema/context" - xmlns:tx="http://www.springframework.org/schema/tx" - xmlns:jpa="http://www.springframework.org/schema/data/jpa" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/data/jpa - http://www.springframework.org/schema/data/jpa/spring-jpa.xsd - http://www.springframework.org/schema/tx - http://www.springframework.org/schema/tx/spring-tx.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context.xsd"> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" + xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- ========================= RESOURCE DEFINITIONS ========================= --> @@ -29,23 +22,9 @@ <!-- (in this case, JDBC-related settings for the JPA EntityManager definition below) --> <context:property-placeholder location="classpath:spring/jdbc.properties"/> - <!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= --> - - <!-- - Activates various annotations to be detected in bean classes: Spring's - @Required and @Autowired, as well as JSR 250's @PostConstruct, - @PreDestroy and @Resource (if available) and JPA's @PersistenceContext - and @PersistenceUnit (if available). - --> - <context:annotation-config/> - - <!-- - Instruct Spring to perform declarative transaction management - automatically on annotated classes. - - for mode="aspectj"/ see SPR-6392 - --> - <tx:annotation-driven/> + <!-- enables scanning for @Transactional annotations --> + <tx:annotation-driven /> + <beans profile="jpa,spring-data-jpa"> <!-- JPA EntityManagerFactory -->