Tag: aop

在切入点内获取带注释的参数

我有两个注释@LookAtThisMethod和@LookAtThisParameter ,如果我使用@LookAtThisMethod对方法进行@LookAtThisMethod ,我怎样才能提取用@LookAtThisParameter注释的所述方法的参数? 例如: @Aspect public class LookAdvisor { @Pointcut(“@annotation(lookAtThisMethod)”) public void lookAtThisMethodPointcut(LookAtThisMethod lookAtThisMethod){} @Around(“lookAtThisMethodPointcut(lookAtThisMethod)”) public void lookAtThisMethod(ProceedingJoinPoint joinPoint, LookAtThisMethod lookAtThisMethod) throws Throwable { for(Object argument : joinPoint.getArgs()) { //I can get the parameter values here } //I can get the method signature with: joinPoint.getSignature.toString(); //How do I get which parameters are annotated with @LookAtThisParameter? […]

在春季项目中AOP最常见的用途是什么

在审查了AOP模式后,我对我在春季项目中如何使用它以及如何使用它的方式感到不知所措。 我想将它用作所有财务业务逻辑的审计日志系统。 它似乎很容易整合。 但我想听听你对此的看法。 问题是 – 对于这种模式,我应该考虑哪些其他用途? 我不介意重构我目前使用AOP的逻辑,只要它有好处。

如何使用AOP拦截参数中的super方法调用?

我正在扩展一个类并重写一个方法。 我想要做的就是调用super,但是调用一个被修改的参数可以调用其方法之一。 一个例子使它更清楚: // Foo is an interface and also this method is part of an interface @Override public void foo(Foo foo) { // I want to intercept the call to foo.bar() in super super.foo(foo); } 我宁愿使用一个不需要自己编译器的工具。 什么是最佳的?

AspectJ可以穿过sun.net。*包吗?

我正在使用AspectJ来拦截java.net.Socket调用。 我创造了非常简单的方面 after(): call(* java.net.Socket.connect(..)) { System.out.println(“Connect intercepted!”); } 和aop.xml 当调用堆栈是这样的,那么我可以看到控制台输出: java.lang.Exception at com.iggroup.lightstreamer.nwtp.SocketExceptionLoggingAspect.ajc$after$com_iggroup_lightstreamer_nwtp_SocketExceptionLoggingAspect$2$6e16217c(SocketExceptionLoggingAspect.aj:39) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:91) at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:596) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475) at com.iggroup.lightstreamer.nwtp.users.SsoRestClientImpl.lambda$0(SsoRestClientImpl.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at […]

使用AspectJ实现虫洞模式

我正在寻找使用AspectJ的虫洞模式实现的一个例子(如果Guice AOP有能力实现这一点,将会感兴趣)。 蠕虫洞本质上允许您沿着调用流传递其他参数,例如: // say we have class foo { public int m0 int a, int b) { return m1(a,b); } public int m1 int a, int b) { return m2(a,b); } public int m2 int a, int b) { return a+b; } } // and I wanted in a non-invasive manner to pass a […]

带有注释的类的子类的@AspectJ切入点

我正在寻找一个切入点,该切入点匹配将类与特定注释子类化的类中的方法执行。 优秀的AspectJ备忘单帮我创建了以下切入点: within(@my.own.annotations.AnnotationToMatch *) && execution(* *(..)) 这匹配带有@AnnotationToMatch的类A的所有方法调用,但不匹配扩展A的类B的方法。如何匹配两者?

ClassCastException $ Proxy无法使用aop强制转换为

我正在使用spring通过bean创建对象。 现在我尝试使用aop创建相同的对象,我得到$ Proxy无法转换为SaleRoomexception。 以前的xml是: 我使用以下代码创建销售: ApplicationContext context = new FileSystemXmlApplicationContext(SalesManager.getSalesSourceFile()); SaleRoom saleRoom; List salesNames = new LinkedList(); List allSales = new LinkedList(); // Get all sales id’s for beans NodeList salesNodeList = salesDoc.getElementsByTagName(“bean”); for (int i = 0; i < salesNodeList.getLength(); i++) { Node nNode = salesNodeList.item(i); salesNames.add(((Element) nNode).getAttribute("id").toString()); } for (String saleName : salesNames) […]

如何使用AspectJ支持在Eclipse中创建Maven项目?

似乎必须在使用某些特定于Eclipse的配置或“Maven项目”的“AspectJ项目”之间进行选择,然后尝试正确获取AspectJ的XML配置。 是否有一些我缺少的Eclipsefunction,或者是否有一个“预制”/教程项目,我可以作为一个开始使用? PS:我正在使用Eclipse 3.7(Indigo)。

旧的“@Transactional来自同一类”的情况

原始问题的概要:使用带有AOP代理的标准Spring事务,不可能从同一类中的非@Transactional-marked方法调用@Transactional-marked方法并且在事务内(特别是由于前面提到的)代理)。 据说在AspectJ模式下使用Spring Transactions可以实现这一点,但它是如何完成的? 编辑:使用加载时编织在AspectJ模式下Spring事务的完整纲要: 将以下内容添加到META-INF/spring/applicationContext.xml : (我假设您已经在应用程序上下文中设置了AnnotationSessionFactoryBean和HibernateTransactionManager 。您可以将transaction-manager=”transactionManager”作为属性添加到标记中,但是如果值为事务管理器bean的id属性实际上是“ transactionManager ”,然后它是多余的,因为“ transactionManager ”是该属性的默认值。) 添加META-INF/aop.xml 。 内容如下: 将aspectjweaver-1.7.0.jar和spring-aspects-3.1.2.RELEASE.jar到classpath 。 我使用Maven作为我的构建工具,所以这里是项目的POM.xml文件的声明: org.aspectj aspectjweaver 1.7.0 org.springframework spring-aspects 3.1.2.RELEASE spring-instrument-3.1.2.RELEASE.jar不需要作为classpath上的 ,但你仍然需要它在某处,以便你可以使用-javaagent JVM标志指向它,如下所示: -javaagent:full\path\of\spring-instrument-3.1.2.RELEASE.jar 我在Eclipse Juno工作,所以为了设置这个,我去了Window – > Preferences – > Java – > Installed JREs。 然后我在列表框中单击选中的JRE,然后单击列表框右侧的“编辑…”按钮。 生成的弹出窗口中的第三个文本框标记为“默认VM参数:”。 这是应该键入-javaagent标志或复制+粘贴的位置。 现在我的实际测试代码类。 首先,我的主要类TestMain.java : package my.package; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestMain […]

AOPexception处理

我看到Guice和Spring使用AOP联盟进行方法拦截,我一直试图弄清楚如何让AOP联盟拦截和处理某些exception,所以我不必继续编写相同的代码。在每个catch区内再次出现。 但是在审查了游戏之后,看起来AOP联盟并没有提供任何方法来拦截抛出的Throwable s,使得处理程序/拦截器可以执行某些操作(记录exception等),然后确定是否进一步传播exception,或者只是恢复到引发exception的行之后的下一行 : HerpDerp hd = null; if(hd == null) throw new RuntimeException(“Herpyl derp!”); Manny.pacquiao(); 我正在寻找一种AOPexception处理机制,它将拦截RuntimeException并使用业务逻辑来决定是继续传播它还是在Manny.pacquioa()调用时恢复。 如果在Java中无法做到这一点,请告诉我 无论是否可以在Java中执行此操作,是否有办法拦截抛出exception与AOP联盟或我必须去其他地方。 如果我必须去别的地方,在哪里? AspectJ的? 谢谢!