1 准备工作

(按需下载)

2 Spring IDE

help->Eclipse Marketplace->Find"Spring"->install

选择需要的项目安装,重启Eclipse.

安装完记得重启


3 导入所需的包

方法有多种,我贴下我的方法。

项目右键->build path->configure build path->Libraries->add Library->User Library->User Librarys

->New->输入Library name->add External JARs->选择需要的包

->在add Library处勾选刚才的Lib->finish->ok;

我这种办法好像比较麻烦.......

4 入门项目

完整目录

Performer.java

 package com.spring;

 import java.text.SimpleDateFormat;
import java.util.Date; public class Performer {
private Instrument ins;
public Performer(Instrument ins){
this.ins=ins; //与Violin紧密耦合
}
public void play(){
ins.play();
}
}
class Record{
private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void starttime(){
System.out.println(df.format(new Date()));
}
public void endtime(){
System.out.println(df.format(new Date()));
}
}
class Violin extends Instrument { public void play() {
System.out.println("Violin music!");
}
}
class Instrument {
void play(){};
}

PerformerMain.java

package com.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class PerformerMain { public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext apc = new ClassPathXmlApplicationContext("spring.xml");
Performer hello = (Performer) apc.getBean("performer");
hello.play();
} }

Spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="performer" class="com.spring.Performer">
<constructor-arg ref="violin" />
</bean> <bean id="violin" class="com.spring.Violin"></bean>
<bean id="record" class="com.spring.Record"></bean> <aop:config>
<aop:aspect ref="record"> <aop:pointcut expression="execution(* com.spring.Performer.play(..))" id="play"/> <aop:before method="starttime" pointcut-ref="play"/>
<aop:after method="endtime" pointcut-ref="play"/>
</aop:aspect>
</aop:config>
</beans>

运行结果:


注意事项:

xml文件中使用aop标签引入头文件配置

报错:

需要AspectJ的三个包,已在开头给出。


最新文章

  1. 【BZOJ】4001: [TJOI2015]概率论
  2. JavaScript 数组
  3. C# 转换符的重载 显示、隐式转换
  4. php正规则表达式的语法
  5. DEV主从表
  6. 转:如何学习SQL(第二部分:从关系角度理解SQL)
  7. 【C#学习笔记】Hello World
  8. easyui表单提交,后台获取不到值
  9. Java基础知识强化之集合框架笔记62:Map集合之HashMap嵌套HashMap
  10. 【转】 ubuntu12.04更新源
  11. Android L(5.0)源码之手势识别GestureDetector
  12. 20162302 实验一《Java开发环境的熟悉》实验报告
  13. 到底创建了几个String对象?
  14. Linux shell编程 -test
  15. clean exit - waiting for changes before restart
  16. LeetCode题解之 Find Mode in Binary Search Tree
  17. 【MAVEN】如何在Eclipse中创建MAVEN项目
  18. Kudu:支持快速分析的新型Hadoop存储系统
  19. windows 下,CCXT库的安装
  20. physical------Collider 组件参考

热门文章

  1. C++string类字符串学习
  2. 感兴趣的WebGL ,来自微博的一个全景星空图~
  3. Lua的栈及基本栈操作
  4. TTP223 触摸按键
  5. Hive2.0常用函数(对编辑器很无语&#128531;)
  6. python基础:数据类型一
  7. jedis五种数据类型的方法解释
  8. golang结构体json格式化的时间格式
  9. Pycharm中查看内置函数的源码
  10. P2172 [国家集训队]部落战争 二分图最小不相交路径覆盖