From 3fe122db45e742eac04c5f050e6788852b0762b2 Mon Sep 17 00:00:00 2001 From: Mic Date: Mon, 11 Mar 2013 11:04:51 +0800 Subject: [PATCH] moved caching to the Service layer --- .../jdbc/JdbcVetRepositoryImpl.java | 1 - .../petclinic/service/ClinicServiceImpl.java | 2 + src/main/resources/spring/business-config.xml | 43 +++++-------------- 3 files changed, 13 insertions(+), 33 deletions(-) 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 14d3c8eea..58c8614ea 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 findAll() throws DataAccessException { List vets = new ArrayList(); // 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 df628d3b9..6db1fc296 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 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 9ea5c1764..84b500373 100644 --- a/src/main/resources/spring/business-config.xml +++ b/src/main/resources/spring/business-config.xml @@ -1,21 +1,14 @@ - + @@ -29,23 +22,9 @@ - - - - - - - + + +