I hope this is not a duplicate but I could not find a related question/answer for my requirement.
In the application, there is a requirement to apply spring caching annotations (which internally use ehcache) to many of the service layer's methods.
For example, the ContentService class has the following 2 methods.
@Caching(cacheable = { @Cacheable(condition = "#baseObj.isCacheEnabled()", value = "cacheName", key = "#baseObj.getCacheKey()") })
@Order(value = 2)
public ReturnObj getPageContent(BaseObject baseObj);
@Caching(cacheable = { @Cacheable(condition = "#baseObj.isCacheEnabled()", value = "cacheName", key = "#baseObj.getCacheKey()") })
@Order(value = 2)
public ReturnObj getModuleContent(BaseObject baseObj);
As you can see, the following annotations are repeated and redundant in every service method annotations.
@Caching(cacheable = { @Cacheable(condition = "#baseObj.isCacheEnabled()", value = "cacheName", key = "#baseObj.getCacheKey()") })
@Order(value = 2)
Question1 Is there a way I can extend the Caching annotation and move the redundant stuff there instead of littering the classes with the same code ?
For example,
@CustomCaching
@Order(value = 2)
public ReturnObj getPageContent(BaseObject baseObj);
@CustomCaching
@Order(value = 2)
public ReturnObj getModuleContent(BaseObject baseObj);
where CustomCaching interface can extend Spring's Caching interface and apply the commonly required annotations at one place.
Question2
Is there a way that I can specify @Order(value=2)
at one common place and say, apply this annotation to all the methods within a class ?