If you're configuring your application with XML, you can enable annotation-driven caching with the <cache:annotation-driven> element from Spring's cache namespace, as follows:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation="http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-4.3.xsd http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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.3.xsd http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <!-- Enable caching --> <cache:annotation-driven /> <context:component-scan base-
package="com.packt.patterninspring.chapter9.bankapp"/> <!-- Declare a cache manager --> <bean id="cacheManager"
class="org.springframework.cache.concurrent.
ConcurrentMapCacheManager" /> </beans>
As seen in the preceding configuration files, whether you use Java configuration or XML configuration, the annotation @EnableCaching and namespace <cache:annotation-driven> enables Spring's cache abstraction by creating an aspect with pointcuts that trigger off of Spring's caching annotations.
Let's see how to use Spring's caching annotations to define cache boundaries.