Skip to content

Commit f38af8b

Browse files
author
Eugen
committed
Merge pull request eugenp#221 from Doha2012/master
fix cache configuration
2 parents fd6d988 + 23c5dd6 commit f38af8b

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

spring-all/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@
3232
<version>${org.springframework.version}</version>
3333
</dependency>
3434

35+
<!-- aspectj -->
36+
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-aspects</artifactId>
40+
<version>${org.springframework.version}</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.springframework</groupId>
45+
<artifactId>spring-orm</artifactId>
46+
<version>${org.springframework.version}</version>
47+
</dependency>
48+
3549
<!-- persistence -->
3650

3751
<dependency>

spring-all/src/main/java/org/baeldung/caching/example/CustomerDataService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public String getAddress2(final Customer customer) {
4747
* @param customer the customer
4848
* @return the address
4949
*/
50-
@Caching(evict = { @CacheEvict("addresses"), @CacheEvict(value = "directory", key = "customer.name") })
50+
@Caching(evict = { @CacheEvict("addresses"), @CacheEvict(value = "directory", key = "#customer.name") })
5151
public String getAddress3(final Customer customer) {
5252
return customer.getAddress();
5353
}
@@ -70,7 +70,7 @@ public String getAddress4(final Customer customer) {
7070
* @param customer the customer
7171
* @return the address
7272
*/
73-
@CachePut(value = "addresses", condition = "#customer.name='Tom'")
73+
@CachePut(value = "addresses", condition = "#customer.name=='Tom'")
7474
// @CachePut(value = "addresses", unless = "#result.length>64")
7575
public String getAddress5(final Customer customer) {
7676
return customer.getAddress();

spring-all/src/main/java/org/baeldung/caching/resouces/config.xml renamed to spring-all/src/main/resources/config.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,34 @@
1212
<cache:annotation-driven />
1313

1414
<context:annotation-config />
15-
<bean class="org.baeldung.caching.config.myAppConfig" />
15+
<bean class="org.baeldung.caching.config.MyAppConfig" />
1616

1717
<!-- the service that you wish to make cacheable. -->
1818
<bean id="customerDataService" class="org.baeldung.caching.example.CustomerDataService" />
1919

20+
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
21+
<property name="caches">
22+
<set>
23+
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" name="directory"/>
24+
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" name="addresses"/>
25+
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" name="addressDemo"/>
26+
</set>
27+
</property>
28+
</bean>
29+
2030
<!-- define caching behavior -->
2131
<cache:advice id="cachingBehavior" cache-manager="cacheManager">
2232
<cache:caching cache="addresses">
2333
<cache:cacheable method="getAddress" key="#customer.name" />
2434
</cache:caching>
2535
</cache:advice>
2636

37+
2738
<!-- apply the behavior to all the implementations of CustomerDataService
2839
interface -->
2940
<aop:config>
3041
<aop:advisor advice-ref="cachingBehavior"
31-
pointcut="execution(*org.baeldung.caching.example.CustomerDataService.*(..))" />
42+
pointcut="execution(* org.baeldung.caching.example.CustomerDataService.*(..))" />
3243
</aop:config>
3344

3445
</beans>

spring-all/src/main/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java renamed to spring-all/src/test/java/org/baeldung/caching/test/SpringCachingBehaviorTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.baeldung.caching.test;
22

3-
import static org.junit.Assert.fail;
4-
53
import org.baeldung.caching.example.Customer;
64
import org.baeldung.caching.example.CustomerDataService;
75
import org.junit.Test;
@@ -11,6 +9,7 @@
119

1210
@Component
1311
public class SpringCachingBehaviorTest {
12+
1413
@Test
1514
public void testCaching() {
1615
@SuppressWarnings("resource")
@@ -19,7 +18,9 @@ public void testCaching() {
1918

2019
final Customer cust = new Customer("Tom", "67-2, Downing Street, NY");
2120
service.getAddress1(cust);
22-
fail("Unable to instantiate the CustomerDataService");
21+
service.getAddress1(cust);
22+
23+
// fail("Unable to instantiate the CustomerDataService");
2324
}
2425

2526
}

0 commit comments

Comments
 (0)