質問

I've seen similar problems posted on stack overflow and on the spring forums but cannot find a solution. When I try to go to the homepage - so this is before I've tried to click on login - I get the following exception:

java.lang.IllegalArgumentException: warning no match for this type name: enteredPassword [Xlint:invalidAbsoluteTypeName]

Here is my 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)) and args(username, enteredPassword)"/>
        <aop:before pointcut-ref="validateUser" method="logLoginAttempt" arg-names="username"></aop:before>
    </aop:aspect>
</aop:config>

</beans>

Here is the 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 is the logging method:

public void logLoginAttempt(String username){
    activityLogger.info("Login attempt by: " + username);   
}

Appreciate any help with this and thanks.

役に立ちましたか?

解決

You have 2 problems in your code

  1. Your pointcut doesn't match the actual package
  2. Your advice method only has a single argument whereas 2 are expected.

For the first fix the package in the pointcut expression. com.company.model.controller.UserValidation should be 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)) and args(username, enteredPassword)"/>
        <aop:before pointcut-ref="validateUser" method="logLoginAttempt" arg-names="username"></aop:before>
    </aop:aspect>
</aop:config>

In this aspect you have specified args(username, enteredPassword) which requires that your advice has 2 parameters.

Add those also to your config and your 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 it from the args clause args(username,..).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top