java - Spring AOP: Trying to use for logging but getting IllegalArgumentException -


i've seen similar problems posted on stack overflow , on spring forums cannot find solution. when try go homepage - before i've tried click on login - following exception:

java.lang.illegalargumentexception: warning no match type name: enteredpassword [xlint:invalidabsolutetypename] 

here xml:

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"  xmlns:context="http://www.springframework.org/schema/context"  xmlns:aop="http://www.springframework.org/schema/aop"  xsi:schemalocation="http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd  http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.1.xsd  http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">   <bean class="com.company.controller.uservalidation" id="uservalidation"/> <bean class="com.company.model.activitylogging" id="activitylogging"/>  <aop:config>     <aop:aspect ref="activitylogging">         <aop:pointcut id="validateuser" expression="execution(* com.company.controller.uservalidation.validateuser(java.lang.string,java.lang.string)) , args(username, enteredpassword)"/>         <aop:before pointcut-ref="validateuser" method="logloginattempt" arg-names="username"></aop:before>     </aop:aspect> </aop:config>  </beans> 

here validateuser() method:

public user validateuser(string username, string enteredpassword) throws noresultexception, passwordincorrectexception{     user user = dal.searchforuser(username);     if(user.getpassword().equals(enteredpassword)){         return user;     }else{         throw new passwordincorrectexception();     } } 

and here logging method:

public void logloginattempt(string username){     activitylogger.info("login attempt by: " + username);    } 

appreciate , thanks.

you have 2 problems in code

  1. your pointcut doesn't match actual package
  2. your advice method has single argument whereas 2 expected.

for first fix package in pointcut expression. com.company.model.controller.uservalidation should com.company.controller.uservalidation.

<aop:config>     <aop:aspect ref="activitylogging">         <aop:pointcut id="validateuser" expression="execution(* com.company.controller.uservalidation.validateuser(java.lang.string,java.lang.string)) , args(username, enteredpassword)"/>         <aop:before pointcut-ref="validateuser" method="logloginattempt" arg-names="username"></aop:before>     </aop:aspect> </aop:config> 

in aspect have specified args(username, enteredpassword) requires advice has 2 parameters.

add config , advice.

<aop:before pointcut-ref="validateuser" method="logloginattempt" arg-names="username,enteredpassword">  public void logloginattempt(string username, string enteredpassword){     activitylogger.info("login attempt by: " + username);    } 

or remove args clause args(username,..).


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -