使用其他 jar 的各个方面
我想要完成的任务如下:
我有一个具有以下结构的服务器。
bin apis services etc...
我想定义一个 API,其中包含服务要使用的方面。说:
@Aspect
public class AuthorizationAspect {
@Pointcut("call(* *()) && @annotation(Authorization)")
public void cutAuthorize() { }
@Before("cutAuthorize()")
public void callFromAuthorizeBefore() {
System.out.println("Test");
}
}
然后我定义服务并用 @Authorization 注释我想要的方法,并且它通过该方面获得切入点。
您应该知道的事情:
- 服务仅使用 API 来编译代码,因此范围是“提供的”,因为 API 已经在服务器中。
- 服务 JAR 是动态加载的,因此它们将驻留在另一个类加载器中。
我的问题是,我该怎么做?我如何定义我的 Maven 工件来实现这一目标?
我注意到,aspectj 插件有一个 weaveDependency 部分,但这也将在服务 JAR 中包含该 API 中的所有类(这是我想避免的)。这是正确的举动吗?
预先感谢,
瑞
What I'm trying to accomplish is the following:
I have a server with the following structure.
bin apis services etc...
I want to define an API that contains an aspect to be used by services. Say:
@Aspect
public class AuthorizationAspect {
@Pointcut("call(* *()) && @annotation(Authorization)")
public void cutAuthorize() { }
@Before("cutAuthorize()")
public void callFromAuthorizeBefore() {
System.out.println("Test");
}
}
Then I define the service and annotate the methods I want with @Authorization and it gets pointcut by that aspect.
Things you should know:
- Services only use the API to compile the code, therefore the scope is "provided", since the API will be already in the server.
- Services JARs are loaded dynamically, so they will reside in another classloader.
My question is, how can I do this? How do I define my maven artifacts to accomplish that?
I noticed that the aspectj plugin has a weaveDependencies section, but this will also include in the service JAR all classes in that API (something that I want to avoid). Is this the right move?
Thanks in advance,
Rui
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 jcabi-aspects 中是如何完成的。您在 API 中声明/编译您的方面,然后使用此 JAR,因为我们在示例中使用了
com.jcabi:jcabi-aspects
:可以在
provided< 中提供您的方面 JAR /code>(或
运行时
)范围。Take a look at how it's done in jcabi-aspects. You declare/compile your aspects in the API and then use this JAR as we
com.jcabi:jcabi-aspects
is being used in the example:It's OK to have your aspects JAR in
provided
(orruntime
) scope.