Java注释-继承以避免冗余注释

Java注释-继承以避免冗余注释,java,annotations,Java,Annotations,我希望这不是重复的,但我找不到与我的要求相关的问题/答案 在应用程序中,需要将spring缓存注释(内部使用ehcache)应用于许多服务层的方法 例如,ContentService类有以下两种方法 @Caching(cacheable = { @Cacheable(condition = "#baseObj.isCacheEnabled()", value = "cacheName", key = "#baseObj.getCacheKey()") }) @Order(value = 2) p

我希望这不是重复的,但我找不到与我的要求相关的问题/答案

在应用程序中,需要将spring缓存注释(内部使用ehcache)应用于许多服务层的方法

例如,ContentService类有以下两种方法

@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);
如您所见,以下注释在每个服务方法注释中都是重复和冗余的

@Caching(cacheable = { @Cacheable(condition = "#baseObj.isCacheEnabled()", value = "cacheName", key = "#baseObj.getCacheKey()") })
@Order(value = 2)
问题1 有没有一种方法可以扩展缓存注释并将多余的东西移到那里,而不是用相同的代码乱丢类

比如说,

@CustomCaching
@Order(value = 2)
public ReturnObj getPageContent(BaseObject baseObj);

@CustomCaching
@Order(value = 2)
public ReturnObj getModuleContent(BaseObject baseObj);
其中CustomCaching接口可以扩展Spring的缓存接口,并在一个位置应用通常需要的注释

问题2
是否有一种方法可以在一个公共位置指定
@Order(value=2)
,并将此注释应用于类中的所有方法

扩展注释是不可能的,虽然不完全相同,但我想你们的要求是类似的