Tag: aop

AOP Spring @AfterReturning无法按预期工作

我正在学习AOP spring并尝试一些例子。 关于@ AfterReturning,我所理解的是只有在目标成功返回并且与切入点匹配时才调用该方法。 但是在我的情况下如下所示,我有一个切入点,它定义了只返回String的所有方法,但是它调用所有的void方法以及返回String的方法。 我的建议: @AfterReturning(value= “execution(* com.aop..CustomerServiceImpl.*(..))”, returning= “string”) public void returnStringPointcut(JoinPoint joinPoint,String string){ System.out.println(“logAfter() is running!”); System.out.println(“String : ” + string); System.out.println(“hijacked : ” + joinPoint.getSignature().getName()); System.out.println(“******”); } 请在下面找到我的Impl课程: public void addCustomer() { // TODO Auto-generated method stub } public String getCustomer() { // TODO Auto-generated method stub return “string”; } public […]

什么是为Spring AOP注入相同服务实例的最佳方式

我是一个使用Spring的@Service构造型注释的ServiceImpl,并且有两个方法,每个方法都使用Spring拦截的自定义注释进行注释。 @Service public class ServiceImpl implements Service{ @CustomAnnotation public void method1(){ … } @AnotherCustomAnnotation public void method2(){ this.method1(); … } } } 现在Spring使用基于代理的AOP方法,因此当我使用this.method1()拦截器@CustomAnnotation将无法拦截此调用时,我们曾经在另一个FactoryClass中注入此服务,这样我们就能够获得代理实例如 – @AnotherCustomAnnotation public void method2(){ someFactory.getService().method1(); … } 我现在使用Spring 3.0.x,这是获取代理实例的最佳方法吗?

有人可以解释这个和目标切入点指示符

我是Spring AOP的新手,正在阅读切入点指示符的文档。 这个和目标指示符对我来说都是一样的。 有人可以用更好/更清洁的例子来解释吗? 谢谢 this – 限制匹配连接点(使用Spring AOP时执行方法),其中bean引用(Spring AOP代理)是给定类型的实例 eg: this(com.xyz.service.AccountService) 代理实现AccountService接口的任何连接点(仅在Spring AOP中执行方法): target – 限制匹配到连接点(使用Spring AOP时执行方法),其中目标对象(被代理的应用程序对象)是给定类型的实例 eg: target(com.xyz.service.AccountService) 目标对象实现AccountService接口的任何连接点(仅在Spring AOP中执行方法) 链接: http : //docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/aop.html

方面在运行时编织

我正在寻找一种Java解决方案,它允许我在运行时使用AOP在已经运行的代码之上编写新代码。 关键是不要求重启JVM。 此外,我想在运行时删除编织,让旧代码在编织之前运行。 我在想AspectJ加载时编织+运行时类加载/卸载会做到这一点。 有人试过吗? 有什么建议? 谢谢。

为Spring MVC / AOP应用程序实现动态菜单

我希望为我的Spring MVC应用程序实现动态可更改的菜单(在添加带注释的方法或控制器时更新)。 我想要的是引入新的注释( @RequestMenuMapping ),它将转到@Controller bean及其方法(就像@RequestMapping一样)。 Heres是我想要的, User类,生成菜单之类的 Users Index | List | Signup | Login 使用以下代码: @Controller @RequestMapping(“user”) @RequestMenuMapping(“Users”) public class User { @RequestMapping(“”) @RequestMenuMapping(“Index”) public String index(/* no model here – just show almost static page (yet with JSP checks for authority)*/) { return “user/index.tile”; } @RequestMapping(“list”) @RequestMenuMapping(“List”) public String list(Model model) { […]

AOP,Spring和事务范围

想象一个事务性的,multithreading的java应用程序,使用spring,jdbc和aop,m个包中的n个类都参与数据库转换。 现在让我们说需要在一个事务中确定一组任意类的范围。 此外,在调用事务时提交事务的范围内始终有一个类T. 让我举一个清晰的例子:给定包A,B,Z和类A.Foo,B.Bar和ZT调用各个类的以下实例(可能由不同的调用者和其他类之间):A。 Foo,B.Bar,A.Foo,ZT只有在调用ZT后才会提交事务。 如果应用程序因任何原因而关闭,除非ZT参与,否则交易将永远不会被提交。 实例可以相互调用,并且如前所述,没有公共入口点从单个入口点(如服务层)调用所有实例,这将成为spring的事务标记的简单目标。 现在的问题是:可以使用方面来解决这个问题吗? 如果是这样,那么基本方法是什么? 谢谢。

Spring AOP创建了额外的bean

我正在玩Spring AOP。 这是一个简单的课程 public class CModel extends Car { private double torqueMeasure = 1; public CModel() { System.out.println(” C-Model constructor”); } } Spring配置就是这样的 … 现在可以; 当我添加aop:config并拦截CModel然后Spring调用CModel构造函数两次。 这意味着Spring创建了2个CModel对象,对吧? 如果我删除AOP配置,那么Spring只创建一个CModel对象。 知道为什么会这样吗? 谢谢。

为什么这个Spring AOP切入点没有被触发?

我正在编写非常基于模式的Spring AOP,这里是.xml tao.zhang.Listener中的方法scream()只打印出一些文本, 并且应该在调用方法callme()时执行。 我有一个名为logger的bean,它有方法log()和callme() public void log(){ callme(); System.out.println(“Hello from logger ~~~~~~~~~~~~~~~~~~~”); } public void callme(){ System.out.println(“I’m called”); } 请注意,callme()由log()调用 现在我有一个调度程序,每5秒调用一次log(): 奇怪的是,没有调用scream() ,但是如果直接调用callme(): scream()被调用! 有什么建议么? 在我看来,这个切入点与另一个方法中调用的方法不匹配……

Spring AOP:@annotation(注释)

我(当然)尝试使用许多我不太了解的结构来维护项目。 在试图找出Spring中的AOP使用过程中,我遇到了带有以下注释的方法: @Around(value =“@ annotation(annotation)”) 所以@Around意味着我们在AOP中执行方法切入点的’around’版本,我明白了。 我不知道其他部分是什么意思。 Spring文档提供以下内容: @annotation – 限制匹配到连接点的主题,其中连接点的主题(在Spring AOP中执行的方法)具有给定的注释 我不知道这意味着什么 – “在Spring AOP中执行的方法”听起来像建议的方法,但我不知道我(或Spring)如何找出建议的方法。 听起来它是具有“给定注释”的方法,但如果是这样,那么给出了什么注释? 这个注释建议了哪些方法? 还有什么意思呢?

为什么服务器抱怨aspectOf丢失?

我正在尝试在AspectJ中注入Spring bean,就像下面显示的代码一样,无论如何我的服务器(WAS Liberty Profile)一直在抱怨方法aspectOf缺失。 我可以知道如何解决这个问题? 应用程序的context.xml 上下文文件A.XML JAVA代码 @Aspect public class LoggingAspect { … }