From 23c5dd64f9064d43e7627d06a0cab517dc8fccc3 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 22 Jun 2015 21:14:40 +0200 Subject: [PATCH] fix cache configuration --- spring-all/pom.xml | 14 ++++++++++++++ .../caching/example/CustomerDataService.java | 4 ++-- .../caching/resouces => resources}/config.xml | 15 +++++++++++++-- .../caching/test/SpringCachingBehaviorTest.java | 7 ++++--- 4 files changed, 33 insertions(+), 7 deletions(-) rename spring-all/src/main/{java/org/baeldung/caching/resouces => resources}/config.xml (67%) rename spring-all/src/{main => test}/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java (88%) diff --git a/spring-all/pom.xml b/spring-all/pom.xml index 99faa2b295..f059209f36 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -32,6 +32,20 @@ ${org.springframework.version} + + + + org.springframework + spring-aspects + ${org.springframework.version} + + + + org.springframework + spring-orm + ${org.springframework.version} + + diff --git a/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java b/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java index 4c1c97adb8..86026de93a 100644 --- a/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java +++ b/spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java @@ -47,7 +47,7 @@ public class CustomerDataService { * @param customer the customer * @return the address */ - @Caching(evict = { @CacheEvict("addresses"), @CacheEvict(value = "directory", key = "customer.name") }) + @Caching(evict = { @CacheEvict("addresses"), @CacheEvict(value = "directory", key = "#customer.name") }) public String getAddress3(final Customer customer) { return customer.getAddress(); } @@ -70,7 +70,7 @@ public class CustomerDataService { * @param customer the customer * @return the address */ - @CachePut(value = "addresses", condition = "#customer.name='Tom'") + @CachePut(value = "addresses", condition = "#customer.name=='Tom'") // @CachePut(value = "addresses", unless = "#result.length>64") public String getAddress5(final Customer customer) { return customer.getAddress(); diff --git a/spring-all/src/main/java/org/baeldung/caching/resouces/config.xml b/spring-all/src/main/resources/config.xml similarity index 67% rename from spring-all/src/main/java/org/baeldung/caching/resouces/config.xml rename to spring-all/src/main/resources/config.xml index fd54e85164..e04692ea22 100644 --- a/spring-all/src/main/java/org/baeldung/caching/resouces/config.xml +++ b/spring-all/src/main/resources/config.xml @@ -12,11 +12,21 @@ - + + + + + + + + + + + @@ -24,11 +34,12 @@ + + pointcut="execution(* org.baeldung.caching.example.CustomerDataService.*(..))" /> diff --git a/spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java b/spring-all/src/test/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java similarity index 88% rename from spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java rename to spring-all/src/test/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java index c39e4bfa87..0b3edaffb3 100644 --- a/spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java +++ b/spring-all/src/test/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java @@ -1,7 +1,5 @@ package org.baeldung.caching.test; -import static org.junit.Assert.fail; - import org.baeldung.caching.example.Customer; import org.baeldung.caching.example.CustomerDataService; import org.junit.Test; @@ -11,6 +9,7 @@ import org.springframework.stereotype.Component; @Component public class SpringCachingBehaviorTest { + @Test public void testCaching() { @SuppressWarnings("resource") @@ -19,7 +18,9 @@ public class SpringCachingBehaviorTest { final Customer cust = new Customer("Tom", "67-2, Downing Street, NY"); service.getAddress1(cust); - fail("Unable to instantiate the CustomerDataService"); + service.getAddress1(cust); + + // fail("Unable to instantiate the CustomerDataService"); } }