fix cache configuration
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
|
||||
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
|
||||
">
|
||||
|
||||
<cache:annotation-driven />
|
||||
|
||||
<context:annotation-config />
|
||||
<bean class="org.baeldung.caching.config.myAppConfig" />
|
||||
|
||||
<!-- the service that you wish to make cacheable. -->
|
||||
<bean id="customerDataService" class="org.baeldung.caching.example.CustomerDataService" />
|
||||
|
||||
<!-- define caching behavior -->
|
||||
<cache:advice id="cachingBehavior" cache-manager="cacheManager">
|
||||
<cache:caching cache="addresses">
|
||||
<cache:cacheable method="getAddress" key="#customer.name" />
|
||||
</cache:caching>
|
||||
</cache:advice>
|
||||
|
||||
<!-- apply the behavior to all the implementations of CustomerDataService
|
||||
interface -->
|
||||
<aop:config>
|
||||
<aop:advisor advice-ref="cachingBehavior"
|
||||
pointcut="execution(*org.baeldung.caching.example.CustomerDataService.*(..))" />
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
@@ -1,25 +0,0 @@
|
||||
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;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringCachingBehaviorTest {
|
||||
@Test
|
||||
public void testCaching() {
|
||||
@SuppressWarnings("resource")
|
||||
final ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
|
||||
final CustomerDataService service = context.getBean(CustomerDataService.class);
|
||||
|
||||
final Customer cust = new Customer("Tom", "67-2, Downing Street, NY");
|
||||
service.getAddress1(cust);
|
||||
fail("Unable to instantiate the CustomerDataService");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user