当前位置: 代码迷 >> Java相关 >> [开源]发个spring中aspectj的test
  详细解决方案

[开源]发个spring中aspectj的test

热度:213   发布时间:2007-03-29 16:13:42.0
[开源]发个spring中aspectj的test

package org.aaa;

public interface IBean {
public void hello();
}



package org.aaa;

public class BeanImpl implements IBean {
public void hello(){
System.out.println("hello world!");
//throw new MyException();
}
}

package org.aaa;

public class MyException extends RuntimeException {
public MyException(){
super();
}
public String toString(){
return "MyException!";
}
}


package org.aaa;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test {

public static void main(String[] args) {
ApplicationContext app=new ClassPathXmlApplicationContext("applicationContext.xml");
IBean hello=(IBean)app.getBean("hello");
hello.hello();
}

}


package org.aaa;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class MAspect {
@Pointcut("execution(* org.aaa.IBean.*(..))")
public void method(){}
@Before("method()")
public void before(){
System.out.println("before");
}
@After("method()")
public void after(){
System.out.println("after");
}
@Around("method()")
public Object around(ProceedingJoinPoint p) throws Throwable{
Object value=p.proceed();
return value;
}
@AfterReturning("method()")
public void afterReturn(){
System.out.println("afterRetruning");
}

@AfterThrowing("method()")
public void exception(){
System.out.println("exception!!!!");
}
}

[此贴子已经被作者于2007-3-29 16:15:09编辑过]

搜索更多相关的解决方案: spring  test  aspectj  开源  

----------------解决方案--------------------------------------------------------

<beans>
<aop:aspectj-autoproxy/>
<bean id="hello" class="org.aaa.BeanImpl"/>
<bean id="aspect" class="org.aaa.MAspect"/>
</beans>

[此贴子已经被作者于2007-3-29 16:18:46编辑过]


----------------解决方案--------------------------------------------------------


----------------解决方案--------------------------------------------------------

失综了这么久.原来在搞spring啊.不过我没看懂.帮你顶.


----------------解决方案--------------------------------------------------------
楼上头像好像换了哦,丘比特之箭,不错不错....
----------------解决方案--------------------------------------------------------
我开学了 上不了网
----------------解决方案--------------------------------------------------------
  相关解决方案