Lai*_*jus 7 java annotations spring-annotations
我正在创建自己的自定义快捷方式注释,如Spring Documentation中所述:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(value = "Custom", readOnly = true)
public @interface CustomTransactional {
}
是否有可能,通过我的自定义注释,我还可以设置其他可用的属性@Transactional?我想能够使用我的注释,例如,像这样:
@CustomTransactional(propagation = Propagation.REQUIRED)
public class MyClass {
}
不,如果您想要额外的属性,则必须以这种方式在自定义注释本身上设置其他属性,这是行不通的:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(value = "Custom", readOnly = true, propagation = Propagation.REQUIRED)
public @interface CustomTransactional {
}
一种解决方案(不好的:-))可能是使用您在场景中看到的一组基本案例来定义多个注释:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(value = "Custom", readOnly = true, propagation = Propagation.REQUIRED)
public @interface CustomTransactionalWithRequired {
}
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(value = "Custom", readOnly = true, propagation = Propagation.SUPPORTED)
public @interface CustomTransactionalWithSupported {
}
| 归档时间: | 
 | 
| 查看次数: | 1544 次 | 
| 最近记录: |