spring入门之环境搭建
本人刚刚接触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入门之环境搭建的更多相关文章
- 【个人笔记】003-PHP基础-01-PHP快速入门-03-PHP环境搭建
003-PHP基础-01-PHP快速入门 03-PHP环境搭建 1.客户端(浏览器) IE FireFox CHROME Opera Safari 2.服务器 是运行网站的基本 是放置程序代码的地方 ...
- Android入门之环境搭建
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/1376935560.html 原创:An ...
- SpringData系列一 Spring Data的环境搭建
本节作为主要讲解Spring Data的环境搭建 JPA Spring Data :致力于减少数据访问层(DAO)的开发量.开发者唯一要做的就是声明持久层的接口,其他都交给Spring Data JP ...
- scala 入门Eclipse环境搭建
scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld IDE选择并下载: scala for eclipse 下载: http://scala-ide.org/downloa ...
- 新手嘛,先学习下 Vue2.0 新手入门 — 从环境搭建到发布
Vue2.0 新手入门 — 从环境搭建到发布 转自:http://www.runoob.com/w3cnote/vue2-start-coding.html 具体文章详细就不搬了,步骤可过去看,我这就 ...
- scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld
scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld 学习了: http://blog.csdn.net/wangmuming/article/details/3407911 ...
- spring boot 开发环境搭建(Eclipse)
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- 总结Vue 第四天:vue-cli(Vue2.0 新手入门 — 从环境搭建到发布)
总结Vue 第四天:vue-cli(Vue2.0 新手入门 - 从环境搭建到发布) 一.Vue CLI----(Vue2.0 新手入门 - 从环境搭建到发布): ■ CLI是Command-Lin ...
- Spring1:Spring简介、环境搭建、源码下载及导入MyEclipse
框架学习前言 这个模块是面向Spring的,Spring的学习我是这么想的: 1.简单介绍Spring,主要是从网上借鉴一些重点 2.尽量说明清楚Spring的使用方法以及细节点 3.尽量以自己的理解 ...
随机推荐
- PHP中单引号和双引号的区别
双引号里面的字段会经过编译器解释,然后再当作HTML代码输出:单引号里面的不进行解释,直接输出: PHP引号使用原则 1.字符串的值用单引号 2.PHP中尽量用单引号,HTML代码全部用双引号 3.在 ...
- 如何给两个swiper建立关系
单个swiper已经满足不了需求了. 各种花式轮播已经慢慢进入市场.swiper该如何立足,那么请看. <div class="swiper-container"> & ...
- Linux编程之select
select系统调用的的用途是:在一段指定的时间内,监听用户感兴趣的文件描述符上可读.可写和异常等事件. select 机制的优势 为什么会出现select模型? 先看一下下面的这句代码: int i ...
- java编码详解
举个例子 我们在开发过程中,特别是多种编码格式并存的情况下,很容易遇到乱码问题. 假如有一个GBK编码java文件,然后再使用-Dfile.encoding=GBK参数,写入的文件中哪些是乱码呢.那如 ...
- oracle 树形表结构查询 排序
oracle 树形表结构排序 select * from Table start with parentid is null connect by prior id=parentid order SI ...
- 小程序解析html标签wxPrase插件
微信小程序的标签和原来我们习惯用的标签是不一样的,例如视图容器标签小程序是view,然而html就很多比如常用的div就和小程序的view类似. 通常我们在开发小程序(从列表页跳转到详情页)通过富文本 ...
- DataFrame操作方式
DataFrame/DataSet 操作 Databricks 不止一次提到过希望未来在编写 Spark 应用程序过程中,对于结构化/半结构化数据,使用 Datasets(DataFrame 的扩展) ...
- 开源搜索引擎abelkhan
发起一个开源项目http://www.abelkhan.com/ 目前而言,已经用python编写了一个网络爬虫抓取页面,和一个简单的前端 网络爬虫,已经有很多高手写过,我基本上奉行了拿来主义, 得益 ...
- 【Android Developers Training】 68. 序言:添加动画
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- Ext TabPanel tabbar添加按钮
tabPanel tabbar添加按钮 this.tabPanel = Ext.create('Ext.tab.Panel', { tabBar:{ items:[{ //组件靠右 xtype: 't ...