错误提示:

解决方法1:指定execution

在执行目标方法之前指定execution

解决方法2:可能是execution写错了。请仔细检查。

其他——execution参数设置(带问好的可以不配置,否则必须配置):

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)throws-pattern?)

returning type pattern,name pattern, and parameters pattern是必须的.

modifiers-pattern:可以是public等。。

ret-type-pattern:返回值类型;可以为*表示任何返回值,全路径的类名等.

name-pattern()方法名和参数

throws-pattern异常。。。

例如:

import org.aspectj.lang.annotation.Aspect;

import org.aspectj.lang.annotation.Before;

import org.springframework.stereotype.Component;

//把这个类声明为一个切面,需要把该类放入到IOC容器中

@Aspect

@Component

public class LoggingAspect {

//声明该方法是一个前置通知:在目标方法之前执行

@Before("execution(public int lixiuming.spring.aop.impl.ArithmeticCaculator.add(int, int) )")

public void beforeMethod(){

System.out.println("the method begins with");

}

}

接口:

import org.springframework.stereotype.Service;

@Service

public interface ArithmeticCaculator {

int add(int i,int j);

int sub(int i,int j);

int mul(int i,int j);

int div(int i,int j);

}

测试方法:

public class Main {

public static void main(String[] args) {

ApplicationContext cxt = new ClassPathXmlApplicationContext("ApplicationContext.xml");

ArithmeticCaculator arithmeticCaculator =  cxt.getBean(ArithmeticCaculator.class);

int result = arithmeticCaculator.add(3, 6);

System.out.println("result:"+result);

}

}

实现方法:

import org.springframework.stereotype.Component;

@Component

public class ArithmeticCaculatorImpl2 implements ArithmeticCaculator {

@Override

public int add(int i, int j) {

int result = i+j;

return result;

}

@Override

public int sub(int i, int j) {

int result = i-j;

return result;

}

@Override

public int mul(int i, int j) {

int result = i*j;

return result;

}

@Override

public int div(int i, int j) {

int result = i/j;

return result;

}

}

随机推荐

  1. 多线程中使用HttpContext.Current为null的解决办法

    HttpContext.Current.Server.MapPath(logFile)   这个是得到具体路径的方法  正常情况下是可以的 多线程情况下就为null 下边的代码原本的作用是把网站的异常 ...

  2. Bootstrap 历练实例 - 折叠(Collapse)插件方法

    方法 下面是一些折叠(Collapse)插件中有用的方法: 方法 描述 实例 Options:.collapse(options) 激活内容为可折叠元素.接受一个可选的 options 对象. $(' ...

  3. shell脚本,利用awk计算指定范围内的和。

    期望得到结果如下: vivi 42800Tom 32500John 104500 解题方法如下: 1.利用数组来进行解题.

  4. IBM MQ安装

    一.下载MQ 可以去官方网站下载,我这次下了一个下载器从官方,然后通过下载器进行MQ的下载. 地址:https://www.ibm.com/developerworks/cn/downloads/ws ...

  5. Oracle 数字处理函数

    数字处理函数 ① mod(number1,number2) 取余数的函数,比如mod(10,3) = 10/3 = 1. ② round(number,num_ditigs) .trunk(numbe ...

  6. forEach 以及 IE兼容

      语法 array.forEach(function(currentValue, index, arr), thisValue) 参数 参数 描述 function(currentValue, in ...

  7. vue 中有时候是数据没有同步的问题

    1,在项目中,在做表格的数据渲染的时候,表格中有input标签的数据来进行双向绑定, this.$set(this.tableTitle.money, index, money[index]+isMo ...

  8. JS:字符串转成json数据,和json转成字符串方法 iframe获取父级传过来的数据

    字符串转成json数据,和json转成字符串方法 //转为JSON adinfo=JSON.parse(adinfo) //转为字符串 adinfo=JSON.stringify(adinfo) 大概 ...

  9. 第1章 VMware中安装CentOS7

    目录 1.1 下载CentOS7安装包 1.2 VMware中新建虚拟机 1.3 安装操作系统 本章讲解在VMware中安装CentOS虚拟机的步骤.使用的VMware Workstation版本为1 ...

  10. psutil——获取系统信息的Python第三方模块

    本文摘自廖雪峰大神个人网站:https://www.liaoxuefeng.com/wiki/1016959663602400/1183565811281984 用Python来编写脚本简化日常的运维 ...