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

eclipse下的spring环境配置

时间:2016-02-20 16:00:44      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

1) 工具: (1) jdk

             (2) spring.jar  、commons-logging-1.1.1.jar (因为只是做的简单的demo,所以就只用这两个jar包)

spring.jar 是包含有完整发布模块的单个jar 包。但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2.jar。

commons-logging.jar 包是使用spring的必备包。用来记录程序运行时的活动的日志记录。

在IDE中导入jar后就可以开始编写测试了

2) 在src下写配置文件 

技术分享

 

相关文件如下:spring-demo.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-2.0.xsd">  
    
    <bean id="testBean" class="com.gdut.springdemo.Spring">
        <property name="mySpring">
            <value>This is my first spring!</value>
        </property>
    </bean>
</beans>

测试类:Spring.java

package com.gdut.springdemo;

public class Spring {
    private String mySpring;
        
    public void show(){
        System.out.println("--message--"+getMySpring());
    }

    public String getMySpring() {
        return mySpring;
    }
    public void setMySpring(String mySpring) {
        this.mySpring = mySpring;
    }
}

TestSpring.java

package com.gdut.springdemo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class TestSpring {
    public static void main(String[] args) {
        ApplicationContext ctx=new FileSystemXmlApplicationContext("src/spring-demo.xml");
        Spring spring=(Spring) ctx.getBean("testBean");
        spring.show();
    }

}

控制台打印: --message--This is my first spring!

 

eclipse下的spring环境配置

标签:

原文地址:http://www.cnblogs.com/myseries/p/5203272.html

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