码迷,mamicode.com
首页 > 编程语言 > 详细

Spring 开发第一步

时间:2014-10-25 15:40:58      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   java   for   sp   

   经过今天上午的学习发现spring上手开发一个"hello world"真的非常简单。

开发环境搭建:

1、去spring官网下载spring-framework-3.2.11.RELEASE-dist.zip 。这里带dist的是二进制的jar包,不带dist的是源代码

2、eclipse下新建一个java项目,把上面的包解压后的jar都引用到项目里去,还要再引入一个commons-logging.jar不然会报日志logging factory找不到的错误。

运行《spring in action 3rd Edition》chapter 2中的例子:

bubuko.com,布布扣

package com.springinaction.springidol;

public interface Performer {
    void perform() throws PerformanceException;
}
package com.springinaction.springidol;

public class Juggler implements Performer{
    private int bags = 3;
    public Juggler(){
        
    }
    public Juggler(int bags){
        this.bags = bags;
    }
    public void perform() throws PerformanceException{
        System.out.println("Juggling "+ this.bags + " bags.");
    }
}
<?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">
<!-- Beans declararions go here -->
<bean id="duke" class="com.springinaction.springidol.Juggler"></bean>
</beans>

ApplicationContext ctx = new ClassPathXmlApplicationContext("com/springinaction/springidol/spring-idol.xml");
Performer performer = (Performer)ctx.getBean("duke");
performer.perform();

运行结果:Juggling 3 bags.

 

Spring 开发第一步

标签:style   blog   http   color   io   ar   java   for   sp   

原文地址:http://www.cnblogs.com/lyhero11/p/4050142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!