Spring学习随笔(2):Eclipse下Spring环境配置+入门项目
1 准备工作
(按需下载)
- Eclipse 下载:http://www.eclipse.org/downloads/eclipse-packages/ ;
- Spring 下载:http://repo.spring.io/libs-release-local/org/springframework/spring/ 版本自选;
- Spring aop另需的3个包:http://download.csdn.net/download/lk_lxn/6397895
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的三个包,已在开头给出。
Spring学习随笔(2):Eclipse下Spring环境配置+入门项目的更多相关文章
- Spring学习记录(二)---容器和bean属性配置
下载spring包,在eclipse搭建spring环境. 这步我在eclipse中无法导入包,看网上的: http://sishuok.(和谐)com/forum/blogPost/list/242 ...
- spring 学习(五):spring 事务
spring 学习(五):spring 事务 事务概要 一个数据库事务通常包含了一个序列的对数据库的读/写操作.它的存在包含有以下两个目的: 为数据库操作序列提供了一个从失败中恢复到正常状态的方法,同 ...
- (转)Maven学习总结(七)——eclipse中使用Maven创建Web项目
孤傲苍狼只为成功找方法,不为失败找借口! Maven学习总结(七)——eclipse中使用Maven创建Web项目 一.创建Web项目 1.1 选择建立Maven Project 选择File -&g ...
- Maven学习归纳(一)——简单的环境配置入门
一.Maven的基本概念 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的编译,测试,构建,报告和文档的软件项目管理工具和解决依赖关系的工具. 1.1 项目的构建 项目的构建 ...
- Ant学习-001-ant 基础知识及windows环境配置
一.Ant 概要基础知识 Apache Ant 是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发,用以构建应用,或结合其他开源测试工具例如 git.T ...
- Eclipse下安装及配置maven项目管理工具
①eclipse下maven插件安装. 本地maven安装.环境变量配置完成后,打开eclipse,点击eclipse菜单栏Help->Eclipse Marketplace搜索关键字maven ...
- eclipse php 开发环境配置
一般常用的是eclipse+pdt.我是直接下载的Eclipse for php :http://www.eclipse.org/downloads/packages/eclipse-php-deve ...
- [eShopOnContainers 学习系列] - 02 - vs 2017 开发环境配置
[eShopOnContainers 学习系列] - 02 - vs 2017 开发环境配置 https://github.com/dotnet-architecture/eShopOnContain ...
- 【Mac + Appium + Python3.6学习(三)】之IOS自动化测试环境配置
在做这一节之前先配置我的另一篇文章所需要安装的前提准备条件:<[Mac + Appium学习(一)]之安装Appium环境前提准备> 一.安装IOS自动化测试环境 配置环境: Appium ...
随机推荐
- C++性能榨汁机之伪共享
C++性能榨汁机之伪共享 来源 http://irootlee.com/juicer_false_sharing/ 前言 在多核并发编程中,如果将互斥锁的争用比作“性能杀手”的话,那么伪共享则相当于 ...
- mycat sql timeout 问题解决
发现程序中有个批量update语句需要update 16000多条数据导致超时 2019-11-06 10:35:28.312 pool-9-thread-24 ERROR com.hp.nova.c ...
- sql server 查看表中某一字段的排序规则
SELECT o.name,o.object_id,c.name,c.column_id,c.collation_name FROM sys.columns c JOIN sys.obj ...
- Vue介绍:vue导读2
一.实例中的成员 二.高级指令 三.组件初识 一.实例中的成员 # 计算computed <!DOCTYPE html> <html> <head> <met ...
- Kinect 深度测量原理
和其他摄像机一样,近红外摄像机也有视场.Kinect摄像机的视野是有限的,如下图所示: 如图,红外摄像机的视场是金字塔形状的.离摄像机远的物体比近的物体拥有更大的视场横截面积.这意味着影像的高度和宽度 ...
- js修改元素的属性
<script type="text/javascript"> //给id为nice的元素 添加title属性并赋值为"测试title" funct ...
- Comparator分组测试
import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.u ...
- HDU - 3506 Monkey Party
HDU - 3506 思路: 平行四边形不等式优化dp 这不就是石子归并(雾 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma G ...
- selenium之chromedriver与谷歌浏览器映射,到谷歌71.0版本的
转载出处: https://blog.csdn.net/huilan_same/article/details/51896672
- 数字证书注册审批机构(RA)
1.证书注册审批机构 RA(Registration Authority),数字证书注册审批机构.RA系统是CA的证书发放.管理的延伸.它负责证书申请者的信息录入.审核以及证书发放等工作:同时,对发放 ...