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 ...
随机推荐
- docker启动mysql 自定义配置文件
命令行如下: docker run --name mysql56 -p : -v /home/mysql56/data:/var/lib/mysql -v /home/mysql56/conf:/et ...
- git提交项目到码云
提交代码: git initgit remote add origin 远程仓库地址git pull --rebase origin mastergit add -Agit commit -m &qu ...
- Linux环境下安装Nginx及其使用
https://www.jb51.net/article/136161.htm 一.查看CentOS的版本 ? 1 cat /etc/redhat-release 二.添加资源库 在 CentOS 系 ...
- gogs 搭建
sudo apt-get install nginx sudo apt-get install git sudo apt-get install mysql-server mysql -u root ...
- LLVM的RTTI特性
本文思路来源于http://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html,叙述有不同,望谅解,希望能从其他方面帮助大家了解C++语言的底层实现. 背景 在LLV ...
- 使用jMeter构造大量并发的随机HTTP请求
在前一篇文章使用jMeter构造大量并发HTTP请求进行微服务性能测试里,我介绍了如何用jMeter构造并发HTTP请求.但是通过文中介绍的方式构造的并发请求,其请求参数都是硬编码的'Wang'. 有 ...
- set 集合的函数调用
方法 意义 S.add(e) 在集合中添加一个新的元素e:如果元素已经存在,则不添加 S.remove(e) 从集合中删除一个元素,如果元素不存在于集合中,则会产生一个KeyError错误 S.dis ...
- mysql 忘记密码如何修改
第一步:将服务停掉 /etc/init.d/mysqld stop 第二步:加参数启动服务 cd /application/mysql/bin/ mysqld_safe --skip-grant-ta ...
- identity server4获取token和userInfo
一.简介 IdentityServer4(ids4)是用于ASP.NET Core的OpenID Connect和OAuth 2.0框架.在许多成熟的.net core框架中都完美的集成的该身份服务框 ...
- CentOS下更改yum源
centos下下载工具为yum,对应的源在/etc/yum.repos.d/CentOS-Base.repo文件下,修改其URI中前面的网络地址即可