Book Image

Mastering Spring Application Development

By : Anjana Mankale
Book Image

Mastering Spring Application Development

By: Anjana Mankale

Overview of this book

Table of Contents (19 chapters)
Mastering Spring Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Spring MVC with caching


In this section, let us develop a simple MVC application to demonstrate simple spring caching. Let us start with the configuration.

To enable caching, we need to add the following configuration to the application context.xml file:

<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven />
//your beans
</beans>

<cache:annotation-driven /> will recognize the spring cache annotations @Cacheable and @CacheEvict.

Let us demonstrate an application context.xml file with a simple caching configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework...