eclipse下的spring环境配置

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!

 

转载于:https://www.cnblogs.com/myseries/p/5203272.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值