是否可以在 Java SE 环境中使用 javax.interceptor? [英] Is it possible to use javax.interceptor in a Java SE environment?

查看:22
本文介绍了是否可以在 Java SE 环境中使用 javax.interceptor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 AOP 来解决特定问题,但它是一个小型的独立 Java 程序(没有 Java EE 容器).

I need to use AOP to solve a particular issue, but it is a small standalone Java program (no Java EE container).

我可以使用 javax.interceptor 功能,还是必须下载一些 3rd-party AOP 实现?如果可能,我宁愿使用 Java SE SDK 附带的内容.

Can I use javax.interceptor functionality, or do I have to download some 3rd-party AOP implementation? I'd rather use what comes with the Java SE SDK if at all possible.

推荐答案

如果您不使用任何类型的容器,那么您的应用程序将无法使用 Java EE 拦截器 API 的实现.

If you are not using a container of any sort then there will not be an implementation of the Java EE interceptor API available to your application.

您应该转而使用 AOP 解决方案,例如 AspectJ,在线提供了大量教程和示例.但是,我会尽量坚持使用遵循最新版本和最佳实践的示例,因为那里有很多旧的东西.

You should instead look to use an AOP solution like AspectJ, for which there is a large amount of tutorials and examples online. However, I would be careful to try to stick to examples that follow the newest versions and best practices since there is a lot of old stuff out there.

如果您已经在使用 Spring 框架,那么 Spring AOP 可能会满足您的要求.这将更容易集成到您的应用程序中,尽管它不会为您提供 AspectJ 的所有功能.

If you are already using the Spring framework then Spring AOP may meet your requirements. This will be significantly easier to integrate into your application, although it does not give you all of the features of AspectJ.

这篇关于是否可以在 Java SE 环境中使用 javax.interceptor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆