• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

spring aop not supporing aspectJ annotation

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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()")

 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic