Spring学习笔记(一)Spring环境搭建

来源:互联网 发布:ios6.1.3软件源 编辑:程序博客网 时间:2024/06/11 00:34

一:Spring简介

     Spring 作者:Rod Johnson;

     官方网站:http://spring.io/
      最新开发包及文档下载地址:http://repo.springsource.org/libs-release-local/org/springframework/spring/

      核心思想:IOC 控制反转;AOP 面向切面;

二:Spring环境搭建

     1.先将核心架包导入工程


    2.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.xsd"></beans>
三:简单Spring示例

     首先写个HelloWorld类

package com.zhu.test;public class HelloWorld {public void test(){System.out.println("Hello Spring !!!");}}

     然后在xml配置文件中加上

<bean name="helloWorld" class="com.zhu.test.HelloWorld"></bean>
    测试类

public class Test {public static void main(String[] args) {ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");HelloWorld hw=(HelloWorld) ac.getBean("helloWorld");hw.test();}}

    输出结果:


原创粉丝点击