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原理还不是很懂 搞了挺久也没弄明白 求帮忙解答!!
解决方案 »
- 求一个使用Ajax的方式实现两级联动的例子。。要全
- 用spring邮件发送有时候好用,有时候出现下面错误。为什么?
- JPA中感觉OneToOne毫无意义
- 请教关于jquery的插件datagrid的几个问题,
- hibernate hql语句问题
- hibernate order by 的问题
- 几道Java填空题,请高手帮忙帮忙!
- 利用JAVA开发windows应用程序(类似CS风格的程序)的可行性论证!
- 新手提问:JDBC:ODBC与SQL SERVER 2000数据库的连接!没辙了!(一次只能放100分,问题解决后另一百分再开一贴!)
- jboss3.22+eclipse2.1中运行测试出现的错误,帮忙了~~~~~~~~~~~~
- 刚刚接触j2EE开发 有点不明白的
- 求助
具体可在beans.xml中加标记:<aop:aspectj-autoproxy/>
仔细看了下,
这里的AspectHeelo有拼写错误。