public class HelloBean { //这是一个hellobean类
private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
public void sayHello(String name){
System.out.println("Hello"+name);
}
public void sayBye(String name){
System.out.println("Bye"+name);
}}
@Aspect //在AspectHello这个类 声明了切面 切入点 通知
public class AspectHello {
@Pointcut("execution(public * *(..))")
public void fooExecution(){}
@Before("AspectHeelo.fooExecution()")
public void DoBefore(){
System.out.println("before");
} @AfterReturning("AspectHeelo.fooExecution()")
public void DoAfter(){
System.out.println("after");
}
public static void main(String args[]){
ClassPathResource resourse=new ClassPathResource("applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resourse);
HelloBean hello=(HelloBean)factory.getBean("hellobean");
hello.sayHello("gg");
hello.sayBye("tt");
}
}<beans //这里简单设置了一下配置文件
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/aop/spring-tx-2.5.xsd
">
<bean id="hellobean" class="HelloBean">
</bean>
<bean id="myAspect" class="AspectHello">
</bean></beans>
程序执行之后,运行如下
hello gg
bye tt请问为什么前置通知和后置通知没有出现 我刚学,对spring原理还不是很懂 搞了挺久也没弄明白 求帮忙解答!!
private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
public void sayHello(String name){
System.out.println("Hello"+name);
}
public void sayBye(String name){
System.out.println("Bye"+name);
}}
@Aspect //在AspectHello这个类 声明了切面 切入点 通知
public class AspectHello {
@Pointcut("execution(public * *(..))")
public void fooExecution(){}
@Before("AspectHeelo.fooExecution()")
public void DoBefore(){
System.out.println("before");
} @AfterReturning("AspectHeelo.fooExecution()")
public void DoAfter(){
System.out.println("after");
}
public static void main(String args[]){
ClassPathResource resourse=new ClassPathResource("applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resourse);
HelloBean hello=(HelloBean)factory.getBean("hellobean");
hello.sayHello("gg");
hello.sayBye("tt");
}
}<beans //这里简单设置了一下配置文件
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/aop/spring-tx-2.5.xsd
">
<bean id="hellobean" class="HelloBean">
</bean>
<bean id="myAspect" class="AspectHello">
</bean></beans>
程序执行之后,运行如下
hello gg
bye tt请问为什么前置通知和后置通知没有出现 我刚学,对spring原理还不是很懂 搞了挺久也没弄明白 求帮忙解答!!
解决方案 »
- javaEE开发时遇到连接数据库的问题,数据库是mysql
- struts2 通过第一个Map循环的key去获得第二个Map的值。急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!
- 请教大侠如何实现2个manytoone方法,应该怎么写?
- 用JQuery如何设置文本框的type属性
- 问了很久的Hibernate问题!!!!!!!
- myeclips怎么打开一个已经建立的工程
- 帮个忙,谢谢!!!
- 先奉上100分有jsp(V)+Servlet(C)+Bean(M)不用Struts的入门代码?
- [如果可以给800分]在Jbuilder和weblogic中如何实现下面的多对多的ejb(一个班级对多个教师,一个教师教多个班级,bjrkjsxx为bjxx和jsxx之
- J2EE开发环境配置要求?(在线等待)
- 刚刚接触j2EE开发 有点不明白的
- 求助
具体可在beans.xml中加标记:<aop:aspectj-autoproxy/>
仔细看了下,
这里的AspectHeelo有拼写错误。