mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
moved caching to the Service layer
This commit is contained in:
parent
e0ba8bfa74
commit
3fe122db45
3 changed files with 13 additions and 33 deletions
|
@ -61,7 +61,6 @@ public class JdbcVetRepositoryImpl implements VetRepository {
|
||||||
* @see org.springframework.samples.petclinic.model.service.ClinicService#findVets()
|
* @see org.springframework.samples.petclinic.model.service.ClinicService#findVets()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(value = "vets")
|
|
||||||
public Collection<Vet> findAll() throws DataAccessException {
|
public Collection<Vet> findAll() throws DataAccessException {
|
||||||
List<Vet> vets = new ArrayList<Vet>();
|
List<Vet> vets = new ArrayList<Vet>();
|
||||||
// Retrieve the list of all vets.
|
// Retrieve the list of all vets.
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.samples.petclinic.service;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.samples.petclinic.model.Owner;
|
import org.springframework.samples.petclinic.model.Owner;
|
||||||
import org.springframework.samples.petclinic.model.Pet;
|
import org.springframework.samples.petclinic.model.Pet;
|
||||||
|
@ -98,6 +99,7 @@ public class ClinicServiceImpl implements ClinicService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
@Cacheable(value = "vets")
|
||||||
public Collection<Vet> findVets() throws DataAccessException {
|
public Collection<Vet> findVets() throws DataAccessException {
|
||||||
return vetRepository.findAll();
|
return vetRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
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:p="http://www.springframework.org/schema/p"
|
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
|
||||||
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||||
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 ========================= -->
|
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
|
||||||
|
|
||||||
|
@ -29,23 +22,9 @@
|
||||||
<!-- (in this case, JDBC-related settings for the JPA EntityManager definition below) -->
|
<!-- (in this case, JDBC-related settings for the JPA EntityManager definition below) -->
|
||||||
<context:property-placeholder location="classpath:spring/jdbc.properties"/>
|
<context:property-placeholder location="classpath:spring/jdbc.properties"/>
|
||||||
|
|
||||||
<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
|
<!-- enables scanning for @Transactional annotations -->
|
||||||
|
<tx:annotation-driven />
|
||||||
<!--
|
|
||||||
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/>
|
|
||||||
|
|
||||||
<beans profile="jpa,spring-data-jpa">
|
<beans profile="jpa,spring-data-jpa">
|
||||||
<!-- JPA EntityManagerFactory -->
|
<!-- JPA EntityManagerFactory -->
|
||||||
|
|
Loading…
Reference in a new issue