错误提示:

解决方法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. 3203 数组做函数参数----排序函数--C语言版

    3203: 数组做函数参数----排序函数--C语言版 时间限制: 1 Sec  内存限制: 128 MB提交: 253  解决: 151[提交][状态][讨论版][命题人:smallgyy] 题目描 ...

  2. Java程序设计第四次作业内容 第五次作业10月9号发布,为第三章全部例题

    第六题:使用判断语句,根据数字,输出对应的中文是星期几? 直接使用一个if语句的情况 int weekDay=3; if(weekDay==1){ sop("今天是星期一"); } ...

  3. swift 循环语句

    // // main.swift // switch // // Created by lanou on 16/10/21. // Copyright (c) 2016年 lanou. All rig ...

  4. 1061: [Noi2008]志愿者招募

    Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 5742  Solved: 3449[Submit][Status][Discuss] Descript ...

  5. shell基础及变量符号

    kernel主要的功能: 1.内存的管理 2.设备驱动程序 3.文件系统的管理 4.进程的管理 5.网络系统   vim /etc/profile.d/ profile(主配置文件) .d(子配置文件 ...

  6. 用随机森林分类器和GBDT进行特征筛选

    一.决策树(类型.节点特征选择的算法原理.优缺点.随机森林算法产生的背景) 1.分类树和回归树 由目标变量是离散的还是连续的来决定的:目标变量是离散的,选择分类树:反之(目标变量是连续的,但自变量可以 ...

  7. 【函数应用】PHP中关于URL的函数处理

    一,函数介绍 1.解析HTTP头信息:get_header() array get_headers ( string 目标URL [, int $format = 0 [如果将可选的 format 参 ...

  8. 使用Navicat连接阿里云ECS服务器上的MySQL数据库

    一.首先要mysql授权 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的mysql数据库密码' WITH GR ...

  9. relu函数为分段线性函数,为什么会增加非线性元素

    relu函数为分段线性函数,为什么会增加非线性元素 我们知道激活函数的作用就是为了为神经网络增加非线性因素,使其可以拟合任意的函数.那么relu在大于的时候就是线性函数,如果我们的输出值一直是在大于0 ...

  10. Scrapy用pipelines把字典保存为csv格式

    import csv class MyProjectPipeline(object): # 保存为csv格式 def __init__(self): # 打开文件,指定方式为写,利用第3个参数把csv ...