错误提示:

解决方法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. 【洛谷5113】Sabbat of the witch(毒瘤分块)

    点此看题面 大致题意: 给你一个序列,要你支持三种操作:区间赋值,区间求和,撤回之前任一区间赋值操作. 分块 这道题应该是一道十分毒瘤的分块题. 这道题要用到的算法并不是很难,但是思维难度是真的高. ...

  2. python_18_三元运算

    # result=值1 if 条件 else 值2 如果条件为真:result=值1,否则result=值2. a,b,c=1,3,5 d=a if b>c else c print(d)

  3. 题解 CF656G 【You're a Professional】

    又是一道假黑题 它教会我们不要看难度标签 虽然这道题的数据范围很小,用cin能过,但我还是要讲一下快读 快读嘛,顾名思义,就是 快速读入 的意思 有同学就会问了,快速读入的原理是什么? 答:它的原理其 ...

  4. 通过cmd查看环境变量名对应的环境变量值

    在VS环境中通常要添加路径,不过基本都是按照往上提供的方法添加变量名形如:$(VC_IncludePath),但是如何通过cmd命令找到真正的路径呢 未完待续……

  5. Bzoj 1081 [Ahoi2009] chess 中国象棋

    bzoj 1081 [Ahoi2009] chess 中国象棋 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1801 状态比较难设,的确 ...

  6. 对于新能源Can数据、电池BMS等字节和比特位的解析

    1.对于1个字节(8个bit)以上的数据需要先进行倒序(因为高位在前 低位在后). CanID CanData 排序后的 字节数据 十进制 分辨率(0.005) 偏移量(40) 0x18FEC117 ...

  7. MySQL - GROUP_CONCAT 使用方法

    如上图,我想把结果集中的三行链接成一行,则可这样写:   总结: GROUP_CONCAT函数默认是用','逗号链接,如果你加上第二个参数,则以',第二个参数值'逗号+第二个参数值链接,如下图     ...

  8. 第五篇:selenium调用IE问题(Protected Mode settings are not the same for all zones)

    代码信息: driver = webdriver.Ie()driver.get('http://www.baidu.com') 问题描述: raise exception_class(message, ...

  9. JZOJ 5773. 【NOIP2008模拟】简单数学题

    5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms  Memory Limits ...

  10. Java Web 基础(一) 基于TCP的Socket网络编程

    一.Socket简单介绍 Socket通信作为Java网络通讯的基础内容,集中了异常.I/O流模式等众多知识点.学习Socket通信,既能够了解真正的网络通讯原理,也能够增强对I/O流模式的理解. 1 ...