spring aop项目中有参方法配置文件显示参数未绑定

问题描述

原始配置文件

<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 https://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">

<!-- this is the object that will be proxied by Spring's AOP infrastructure -->

<bean id="personService" class="DefaultPersonService"/>

<!-- this is the actual advice itself -->

<bean id="profiler" class="SimpleProfiler"/>

<aop:config>

<aop:aspect ref="profiler">

<aop:pointcut id="SomePersonServiceMethod"

expression="execution(* getPerson(String)) and args(name)"/>

<aop:before pointcut-ref="SomePersonServiceMethod"

method="profile"/>

</aop:aspect>

</aop:config>

</beans>

上文来自于spring官方文档,目前希望采用 expression="execution(* DefaultPersonService.getPerson(..))来实现,但是一直报错说参数未能绑定,请问应该如何解决

运行环境

interllij开发版2021.3
jdk1.8
spring 5
该项目为基于maven的spring项目

问题文件下载

【为方便排错,已将项目完整放在和彩云,链接: https://caiyun.139.com/m/i?0d... 提取码:cZUm 】

文件代码补充

public class Person {

private String name;

public Person(String name) {

this.name = name;

}

// the usual getters and setters...

}

public class DefaultPersonService {

public Person getPerson(String name) {

return new Person(name);

}

}

public class SimpleProfiler {

public void profile(String name) throws Throwable {

System.out.println("Profiling for '" + name + "' and '" );

}

}

import org.springframework.beans.factory.BeanFactory;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Boot {

public static void main(final String[] args) throws Exception {

BeanFactory ctx = new ClassPathXmlApplicationContext("beans.xml");

DefaultPersonService person = (DefaultPersonService) ctx.getBean("personService");

person.getPerson("Pengo");

}

}


回答:

execution(* getPerson(String)) and args(name) 无法找到class吧

以上是 spring aop项目中有参方法配置文件显示参数未绑定 的全部内容, 来源链接: utcz.com/p/944361.html

回到顶部