}
}
}
}
}
In Listing 21-18, several annotations are applied at the class level. The @Component annotation
indicates to Spring that it's a Spring bean, while the @Configurable annotation indicates that this advice
should be configured by Spring, by which Spring will create Spring-based AOP proxies for the weaving
classes. Finally, the AspectJ's @Aspect annotation indicates to Spring that it's an AOP advice and will
trigger Spring's support of AspectJ's annotation style.
Within the advice, the ObscenityFilter interface is autowired. The filterObscenities() method is
annotated with @Before along with the pointcut expression, which indicates that it's a before advice and
should intercept all service layer methods. Within the method, the arguments will be checked to see
whether they are assignable to the BlogPosting interface. If that's the case, then the argument should be
either the Entry or Comment object, and the obscenity filter logic will be applied.
To see it in action, you can post a new entry that contains the word crap in either the subject or
body field. Then after you save the entry, you will notice that the word has been translated into penc,
which is the result of the ROT13 algorithm. See Figures 3-6 and 3-7 in Chapter 3.
Scheduling the Job for Purging Audit Data
Another feature that we demonstrated in the SpringBlog application is job scheduling, by which we use
it to implement a daily job to purge the audit history data for Entry and Comment objects that are older
than 30 days. In this section, we will see the implementation in detail.
As you already saw in Chapter 15, task scheduling in Spring is very easy, and in SpringBlog, we use
the annotation style for scheduling the audit data purging job. Listing 21-19 shows the code snippet in
the root-context.xml file that enables annotation-style scheduling support.
Listing 21-19. Configuring Annotation-Based Scheduling in Spring
<!-- Enable Task Scheduling support with annotation -->
<task:scheduler id="myScheduler" pool-size="10"/>
<task:annotation-driven scheduler="myScheduler"/>
In Listing 21-19, the <task:scheduler> tag will cause Spring to create a ThreadPoolTaskScheduler
instance with the specified thread pool size. Then, the <task:annotation-driven> tag enables the
annotation-style scheduling definition. Listing 21-20 shows the HousekeepingService interface, which
defines the data housekeeping jobs that need to be performed by the SpringBlog application.
Listing 21-20. The HousekeepingService Interface
package com.apress.prospring3.springblog.service;
public interface HousekeepingService {
/**
* Scheduled job to purge audit records.
*/
public void auditPurgeJob();
}
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home