POJO 拦截器的最佳方式是什么?
EJB 3.0 附带了拦截器的概念,但话又说回来,它们仅适用于 EJB。我的项目需要为 POJO 类开发拦截器。一种选择是使用 Spring AOP。我想知道是否值得花费一些开销来包含 Spring AOP 所需的 commons-logging、spring-aop、cglib 等库。
EJB 3.0 comes with the concept of Interceptors, but then again they are applicable to EJBs only. My project requires developing Interceptors for POJO classes. One option for this is to use Spring AOP. I want to know if it's worth the overhead of including the libraries such as commons-logging, spring-aop, cglib that are required for Spring AOP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Spring 不仅仅是 Spring AOP,没有 Spring 就无法使用 Spring AOP,我不仅谈论 Spring 库,还谈论 Spring 编程模型!
因此,如果您认为 Spring 对您的应用程序有用(相信我,它对许多应用程序非常有用),那么您可以使用它。 - 但它是一个完整的编程模型,就像EJB一样,不仅仅是一个lib或一个简单的框架。
但我认为每个现代的重要应用程序都应该有一个 ICO 容器,因此 Spring 是您的选择之一。
Spring is much more than Spring AOP, and you can not use Spring AOP without Spring, and I am talking not only to the Spring libs, but to the Spring programming model too!
So if you think Spring is useful for your application (believe me, it is very useful to many application), then you can use it. - But it is a complete programming model, like EJB, not only a lib or a simple framework.
But I think every modern not trivial application should have a ICO container, so Spring is one of the choices you have.
当然,这是值得的,但请注意,如果您需要为 POJO 提供拦截器,那么这还不够:您还需要一个“spring 代理”作为参数传递给您的 jvm(“加载时编织”) ,否则你将无法拦截你的 pojos 方法,或者你将不得不使用“编译时编织”。
简而言之:POJO 必须通过 Spring 创建才能“可拦截”。
CTW(或LTW)使编译(或启动)变得相当慢。
Sure, it's worth, but be aware it won't be enough if you need to have interceptors for you POJOs : You will also need a "spring agent" to be passed as an argument to your jvm ("Load-Time Weaving"), or you won't be able to intercept your pojos methods, or you will have to use "Compile-Time Weaving".
In short : POJOs have to be created via Spring for them to be "interceptable".
CTW (or LTW) makes compilation (or startup) quite slower.