使用AOP或注解来扩展服务功能
我想知道扩展现有功能的最佳方式是什么(可能通过使用 AOP 或注释)。我正在寻找的场景是。
我们有一项服务叫“DisableEmployee”,它使用一个实体“Employee”来进行一些验证,然后禁用对员工的访问。 对于某些客户,我想扩展此功能,DisableEmployee 不仅会禁用访问,还会施加一些罚分。
一种方法是扩展基类,然后添加附加功能。
是否可以(或建议)在这里使用 AOP 和注释;我在其中注释了我的DisableEmployee,然后在编译时将附加代码编织到类中。 (使用方面)我已经阅读了有关 APT 和 Velocity 的内容,它们应该能够帮助我实现它。 我之所以关注 APT,是因为我们可能还必须扩展实体类来添加一些新属性。
采用这种方法的想法是看看我们是否可以将服务扩展分类为横切功能的一种形式(如传统的日志记录、审计......)
提前致谢
I would like to know what is the best way in which I can extend an existing functionality (probably by using AOP or Annotations). The scenario which I am looking for is.
We have one service say DisableEmployee which uses an entity Employee which does some validation and then disables access to employee.
For certain customers I would like to extend this functionality where DisableEmployee not only disables the access but also imposes some penalty points.
One approach would be I extend the base class and then add the additional functionality.
Is it possible (or advisable) to use AOP and annotations here; where in I annotate my DisableEmployee and then at compile time I weave the additional code into the class. (using aspect) I have read about APT and Velocity which should be able to help me in achieving it.
The reason I am looking at APT because we might have to extend the entity classes also to add some new attributes.
The idea of having this approach is to see if we can classify service extension as a form of cross-cutting functionality (like traditional logging, auditing ....)
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题太笼统,无法得到可靠的答案。但目前我看不到 AspectJ 中无法实现的任何内容。
Your question is too general to get reliable answer. But at the moment I cannot see anything what cannot be implemented in AspectJ.