spring mvc - Aspectj advice not getting executed -


i trying code simple aspectj implementation advice not getting executed.

the loggingaspect class getting initiated in console can see s.o.p of constructor

this logging aspect  

getting printed when applicationcontext loaded , controlleraspect initialized. when run main method , output

name: john age :12 

what expecting s.o.p @before advice should printed first , getter methods @afterreturning s.o.p should printed.

there no compilation error , program running advice not getting executed.

according pointcut, advice should implemented on methods of customer class.

i went through of similar problems posted here , not figure out issue implementation.

can 1 figure mistake making , provide resolution ?

here snippet servlet-context.xml

<context:component-scan base-package="main.com.controller"/>                 <!-- enables spring mvc @controller programming model --> <annotation-driven></annotation-driven>        <aop:aspectj-autoproxy/> <!-- aop support -->        <bean id='controlleraspect' class='main.com.logging.loggingaspect' /> <beans:bean id="cust" class="main.com.dtos.customer"</beans:bean>   <resources mapping="/resources/**" location="/resources/" />  <beans:bean  class="org.springframework.web.servlet.view.internalresourceviewresolver">        <beans:property name="prefix" value="/web-inf/views/"/> <beans:property name="suffix" value=".jsp"/> </beans:bean> 

the loggingaspect class :

@aspect public class loggingaspect {     public loggingaspect() {         system.out.println("this logging aspect");     }      @pointcut("execution(* com.dtos.*.*(..))")     public void getmethodpointcut() {}      @afterreturning(pointcut = "getmethodpointcut()", returning="retval")     public void afterreturningadvice(object retval) {         system.out.println("returning:" + retval.tostring() );     }      @before("getmethodpointcut()")     public void printbefore(joinpoint jp ) {         system.out.println("before calling method:"+jp.getsignature()); } 

customer class :

@size(max=30, min=3) @notnull private string name;  @max(150) @notnull private string age;   public customer() {}  public customer(string sname, string sage) {     name = sname;     age = sage; }  public string getname() {     return name; }  public void setname(string name) {     this.name = name; }  public string getage() {     return age; }  public void setage(string age) {     this.age = age; }  @override public string tostring() {     return "customer [name=" + name + ", age=" + age + "]"; } 

main method :

public static void main(string[] args) {     applicationcontext context =          new classpathxmlapplicationcontext("classpath:servlet- context.xml");      customer cust = (customer)context.getbean("cust");     cust.setage("12");     cust.setname("john");      string name = cust.getname();     string age = cust.getage();      system.out.println("name: "+name+" age :"+age); } 

aspectj pom dependencies

<dependency>     <groupid>org.aspectj</groupid>     <artifactid>aspectjrt</artifactid>     <version>1.7.4</version>     <scope>runtime</scope> </dependency> <dependency>     <groupid>org.aspectj</groupid>     <artifactid>aspectjtools</artifactid>     <version>1.7.4</version> </dependency> <dependency>     <groupid>org.aspectj</groupid>     <artifactid>aspectjweaver</artifactid>     <version>1.7.4</version> </dependency> 

just enable close question accepting answer, repeating answer comment:

your spring config implies main.com.dtos.customer, aspect pointcut looking com.dtos.* (without main. prefix) though.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -