我在基于spring mvc的应用程序中使用Aspect来记录活动。我正在使用 @controller 注释来定义我的应用程序中的任何控制器。我在两个不同的包中有两个不同的控制器说
我可以使用
将aspect应用于一个特定的控制器包<aop:config>
<aop:pointcut id="pointcut1"
expression="execution(* package1.*.*(..))"
id="policy1" />
<aop:aspect ref="aspect1" order="1">
<aop:before pointcut-ref="pointcut1" method="before" arg-names="joinPoint" />
<aop:after-returning returning="returnValue" arg-names="joinPoint, returnValue" pointcut-ref="pointcut1" method="after" />
</aop:aspect>
</aop:config>
<bean id="aspect1" class="com......aspectclass" />
我的问题是如何在表达式中指定更多一个不同的包(* package1。。 。(..))**
现在我正在为每个包声明一个单独的切入点,并为每个切入点分别设置一个aop:before
和aop:after
条目。但我认为这应该是定义多个包切入点的理想方式。
答案 0 :(得分:40)
您可以使用布尔运算符:
expression="execution(* package1.*.*(..)) || execution(* package2.*.*(..))"
答案 1 :(得分:11)
如果您使用注释
@Pointcut("within(com.package1..*) || within(com.package2..*)")
答案 2 :(得分:1)
在春季训练中
java.io.FileNotFoundException:
[https://api.github.com/]
at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
at org.kohsuke.github.Requester.parse(Requester.java:612)
at org.kohsuke.github.Requester.parse(Requester.java:594)
at org.kohsuke.github.Requester._to(Requester.java:272)
Caused: org.kohsuke.github.GHFileNotFoundException: \{"message":"Must specify two-factor authentication OTP code.","documentation_url":"
[https://developer.github.com/v3/auth#working-with-two-factor-authentication]
"}
at org.kohsuke.github.Requester.handleApiError(Requester.java:686)
at org.kohsuke.github.Requester._to(Requester.java:293)
at org.kohsuke.github.Requester.to(Requester.java:234)
at org.kohsuke.github.GitHub.checkApiUrlValidity(GitHub.java:703)
at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.checkApiUrlValidity(GitHubSCMSource.java:1348)
at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.retrieve(GitHubSCMSource.java:1401)
at jenkins.scm.api.SCMSource.fetch(SCMSource.java:564)
at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:95)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:295)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
答案 3 :(得分:1)
@Pointcut("execution(* pakageName.anyClassNameX.*(..)) || execution(* pakageName.anyClassNameY.*(..))")
public void allMethods() {
}
@Around("allMethods()")
public Object intercept(ProceedingJoinPoint thisJoinPoint) throws Throwable {
try {
return thisJoinPoint.proceed();
} catch (Exception ex) {
}
}