本人刚刚接触spring,看了一些教程,但是很多概念都不懂(以前没接触过,看着很抽象),所以我觉得通过动手可能会更好的理解并且掌握。看了一些小实例,但是都没有成功,终于在各种尝试之后搭建成功了,现在我就把我的过程简单地展示一下。

  首先准备相应的jar包:spring-framework-3.1.2.RELEASE-with-docs中dist目录下所有jar包(有些多余,但是很方便)  还有spring-framework-3.1.2.RELEASE-dependences中的包(这个spring-framework-3.1.2.RELEASE-dependences.zip不好找,我是一个个百度下面的jar包):com.springsource.org.apache.commons.logging-1.1.1.jar

        com.springsource.org.apache.log4j-1.2.15.jar

         com.springsource.org.apache.commons.collections-3.2.1.jar(相关的jar包我已经传到我的文件中了,不知道怎么去插入链接)。

下载开发工具:SpringSource Tool Suite  参考http://jinnianshilongnian.iteye.com/blog/1413851这个讲的很详细,后面的有点不清晰

接下来的操作就是打开eclipse,建一个javaproject,然后导入jar包

  

如上,然后配置junit环境:选择上图中Add Libraries.. 然后会弹出一个对话框,选择junit,点击下方next  然后选择junit4

这样就ok了

下面就是代码了:

  

其中HelloStaticFactory.java是我自己后来加的 ,与本篇文章无关。

HelloApp.java:

package com.spring.dao;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.test.context.TestExecutionListeners;
import com.spring.service.GreetingService;
import com.spring.service.impl.GreetingServiceImpl;
public class HelloApp {
//这里我使用的是Junit测试的方法,也可以使用main方法来测试,使用Junit测试要导入Junit的Jar包
@Test
public void hello() throws Exception{
ApplicationContext factory=new ClassPathXmlApplicationContext("beans.xml");
GreetingService greetingService=(GreetingService)factory.getBean("greetingService");
greetingService.sayGreeting(); }

GreetingService.java:

package com.spring.service;
public interface GreetingService {
void sayGreeting();
}

GreetingServiceImpl.java:

  

package com.spring.service.impl;
import com.spring.service.GreetingService;
public class GreetingServiceImpl implements GreetingService {
private String greeting; public void setGreeting(String greeting) {
this.greeting = greeting;
}
public GreetingServiceImpl(){}
public GreetingServiceImpl(String greeting){
this.greeting=greeting;
} public void sayGreeting(){
System.out.println(greeting);
}
}

beans.xml:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="greetingService" class="com.spring.service.GreetingService" >
< property name="greeting" value="hello,world"/>
</bean>
</beans> 按照以上方法就可以了,好好看看beans.xml更方便理解整个框架。谢谢大家!

spring入门之环境搭建的更多相关文章

  1. 【个人笔记】003-PHP基础-01-PHP快速入门-03-PHP环境搭建

    003-PHP基础-01-PHP快速入门 03-PHP环境搭建 1.客户端(浏览器) IE FireFox CHROME Opera Safari 2.服务器 是运行网站的基本 是放置程序代码的地方 ...

  2. Android入门之环境搭建

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/1376935560.html 原创:An ...

  3. SpringData系列一 Spring Data的环境搭建

    本节作为主要讲解Spring Data的环境搭建 JPA Spring Data :致力于减少数据访问层(DAO)的开发量.开发者唯一要做的就是声明持久层的接口,其他都交给Spring Data JP ...

  4. scala 入门Eclipse环境搭建

    scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld IDE选择并下载: scala for eclipse 下载: http://scala-ide.org/downloa ...

  5. 新手嘛,先学习下 Vue2.0 新手入门 — 从环境搭建到发布

    Vue2.0 新手入门 — 从环境搭建到发布 转自:http://www.runoob.com/w3cnote/vue2-start-coding.html 具体文章详细就不搬了,步骤可过去看,我这就 ...

  6. scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld

    scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld 学习了: http://blog.csdn.net/wangmuming/article/details/3407911 ...

  7. spring boot 开发环境搭建(Eclipse)

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  8. 总结Vue 第四天:vue-cli(Vue2.0 新手入门 — 从环境搭建到发布)

    总结Vue 第四天:vue-cli(Vue2.0 新手入门 - 从环境搭建到发布) 一.Vue CLI----(Vue2.0 新手入门 - 从环境搭建到发布): ■   CLI是Command-Lin ...

  9. Spring1:Spring简介、环境搭建、源码下载及导入MyEclipse

    框架学习前言 这个模块是面向Spring的,Spring的学习我是这么想的: 1.简单介绍Spring,主要是从网上借鉴一些重点 2.尽量说明清楚Spring的使用方法以及细节点 3.尽量以自己的理解 ...

随机推荐

  1. 卷积神经网络的变种: PCANet

    前言:昨天和大家聊了聊卷积神经网络,今天给大家带来一篇论文:pca+cnn=pcanet.现在就让我带领大家来了解这篇文章吧. 论文:PCANet:A Simple Deep Learning Bas ...

  2. Hibernate入门(三)

    一 Hibernate生成器类 Hibernate中,标签id中的generator标签用于生成持久化类对象的唯一标识.所有的生成器类都实现了org.hibernate.id.IdentifierGe ...

  3. Vue.js组件之间的通信

    导语:组件之间的关系不外乎两种, 父子组件和非父子组件,本文将对两类组件之间的通信方式进行详细阐述. 父子组件间的通信 通信方式1(单向绑定): Props down, Events up (建议使用 ...

  4. 大数据平台搭建-zookeeper集群的搭建

    本系列文章主要阐述大数据计算平台相关框架的搭建,包括如下内容: 基础环境安装 zookeeper集群的搭建 kafka集群的搭建 hadoop/hbase集群的搭建 spark集群的搭建 flink集 ...

  5. 前端学习数据库MYSQL

    这篇文章主要写了 1.数据库MYSQL 2.基本上会遇到的所有SQL语句 数据库可视化软件------Navicat 数据库里边存放的是表,表与表之间是有关联的,而且可以对表进行相关操作(增,删,改, ...

  6. [编织消息框架][netty源码分析]8 Channel 实现类NioSocketChannel职责与实现

    Unsafe是托委访问socket,那么Channel是直接提供给开发者使用的 Channel 主要有两个实现 NioServerSocketChannel同NioSocketChannel 致于其它 ...

  7. 利用Jsoup包爬取网站内容

    一 Jsoup包 下载链接:http://download.csdn.net/detail/u014000832/7994245 二 爬取搜狐新闻网站标题等内容 package com.test1; ...

  8. XCOM2中敌对生物设计分析(Aliens篇)

    Aliens Aliens作为游戏设定中入侵的外星人,有各式外貌及奇特的战斗方式,掌握一些高能科技或利用精神力量进行攻击 Sectoid 使用灵能战斗的外星人,并无高级版本,初级便会使用精神控制,生命 ...

  9. 关闭数据库下的所有连接操作 sql存储过程

    use master go )) as begin ),) declare @spid int set @sql='declare getspid cursor for select spid fro ...

  10. 闭包中this指向window的原因

    var t={ b:1, w:function a(){ var b=2; alert(this.b); //弹出t对象的b属性 alert(b); //弹出a函数的b变量 return functi ...