错误提示:

解决方法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. Ubuntu 上配置静态的ip

    先关掉或卸掉 network-manager.然后,改动/etc/network/interfaces 如下:(由于是静态ip,你当然知道把例子中那些东西改成你自己的)auto lo eth0ifac ...

  2. 2013.10.26工作Fighting(1)

    1.今天虽然花费了六个小时来解决一个功能,最后用一行代码来搞定了. ----遇到问题,解决的办法总是比问题多. 2.给你分配有难度的任务,应该是激动.这样才能挑战自我,学得到很多兴奋的新东西. --- ...

  3. PL/SQL的安装

    一.下载PLSQLDeveloper 网址:https://www.allroundautomations.com/bodyplsqldevreg.html 还需要一个激活码 二.PL/SQL的安装 ...

  4. 利用原生JS实现类似浏览器查找高亮功能(转载)

    利用原生JS实现类似浏览器查找高亮功能 在完成 Navify 时,增加一个类似浏览器ctrl+f查找并该高亮的功能,在此进行一点总结: 需求 在.content中有许多.box,需要在.box中找出搜 ...

  5. mysql零散操作

    添加对外用户 CREATE USER 'admin'@'%' IDENTIFIED BY '!QAZ2wsx'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%'; ...

  6. 整理好的一些mysql表详细操作

    一.创建表的完整语法#语法:create table 库名.表名( 字段名1 类型[(宽度) 约束条件], 字段名2 类型[(宽度) 约束条件], 字段名3 类型[(宽度) 约束条件]);约束条件:是 ...

  7. JZOJ 5809. 【NOIP2008模拟】数羊

    5809. [NOIP2008模拟]数羊 (File IO): input:sheep.in output:sheep.out Time Limits: 1000 ms  Memory Limits: ...

  8. django实现事务

    1.导入模块 from django.db import transaction 2.使用方法 with transaction.atomic(): User.objects.create(name= ...

  9. HUD:3746-Cyclic Nacklace(补齐循环节)

    Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...

  10. poj 2139 奶牛拍电影问题 floyd算法

    题意:奶牛拍一系列电影,n头牛拍m部电影,同一部电影种的搭档们距离为1,求最小距离? 思路:Floyd 图 最短路径 存图: 初始化图 for (int i = 0; i <= n; i++) ...