@Aspect
public class Beforeaspect {
@Before("com.beans.Student.addCustomer()")
public void logBefore(JoinPoint jp)
{
System.out.println("logbefore");
System.out.println("method "+jp.getSignature().getName());
}
}
public class Student implements Studentimpl {
@Override
public void addCustomer() {
// TODO Auto-generated method stub
System.out.println("addcustomer");
}
@Override
public
String addCustomername(String stud) {
// TODO Auto-generated method stub
System.out.println("addcustomername");
return "hello";
}
<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"
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">
<aop:aspectj-autoproxy/>
<bean id="stud" class="com.beans.Student"/>
<bean class="com.beans.Beforeaspect"/>
</beans>
public class
Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext("com/xmlfiles/beans.xml");
Studentimpl studs=(Studentimpl) context.getBean("stud");
// System.out.println(studs.addCustomers());
//studs.addCustomername("aaa");
studs.addCustomer();
}
}
I am using
java 8 and spring 4.3