Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

spring aop not supporing aspectJ annotation

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
 
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I change location of file. (pay note of package, and i change Student to be interface and Studentimpl become class.




@Before("execution( ** com.Student.addCustomer(..))")
or
@Before("execution(** com.Student.addCustomer())")




 
Sergej Smoljanov
Ranch Hand
Posts: 472
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also you can change BeforeAspect (your custom aspect class like this)


note:
@Pointcut("execution (* com.Student.addCustomer())") - you place your pointcut outside @Before and now you can use it as below
and this
@Before(value = "com.BeforeAspect.m()")
 
sidhartha pani
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sergej Smoljanov wrote:Also you can change BeforeAspect (your custom aspect class like this)


note:
@Pointcut("execution (* com.Student.addCustomer())") - you place your pointcut outside @Before and now you can use it as below
and this
@Before(value = "com.BeforeAspect.m()")

 
reply
    Bookmark Topic Watch Topic
  • New Topic