1 Spring 是什么?

  • 具体描述 Spring:
    • 轻量级Spring 是非侵入性的- 基于 Spring 开发的应用中的对象可以不依赖于 Spring 的 API
    • 依赖注入(DI --- dependency injection、IOC)
    • 面向切面编程(AOP --- aspect oriented programming)
    • 容器: Spring 是一个容器, 因为它包含并且管理应用对象的生命周期
    • 框架: Spring 实现了使用简单的组件配置组合成一个复杂的应用. 在 Spring 中可以使用 XML 和 Java 注解组合这些对象
    • 一站式:在 IOC 和 AOP 的基础上可以整合各种企业应用的开源框架和优秀的第三方类库 (实际上 Spring 自身也提供了展现层的 SpringMVC 和 持久层的 Spring JDBC)

Spring模块图:

Eclipse开发Spring时需要安装spring插件:springsource-tool-suite-3.6.3.RELEASE-e4.4.1-updatesite.zip(下载链接:http://spring.io/tools/sts/all 需要FQ)。

2 安装 Eclipse插件

Eclipse—->help—> install new software : 点击Add按钮 ,再点击Archive 选择你刚刚下载的zip文件,这里选择 后面带 spring IDE的四项,并把Contact all updatesite….前面的勾去掉(这个是联网更新),一直点点击 下一步, 最后重启eclipse即可

3 搭建Spring开发环境

新建Java工程 :命名spring-1;并新建Folder 命名为lib(放Spring基本的jar包)

在lib中导入:commons-logging-1.1.3.jar在struts的lib中可以找到,其余四个都在spring-framework-4.1.2.RELEASE的libs文件夹下,记得将lib下的jar包add Build Path;

4 项目结构图:

其中HelloWorld.java

package com.bai.spring.beans;

public class HelloWorld {

private String name;

public void setName(String name){

this.name=name;

}

public void hello(){

System.out.println("hello:"+name);

}

}

在src下新建spring配置文件,命名为applicationcontext.xml

applicationcontext.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">

<!-- 配置bean -->

<bean id="helloworld" class="com.bai.spring.beans.HelloWorld">

<property name="name" value="Spring"></property>

</bean>

</beans>

Main.java

package com.bai.spring.beans;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

public static void main(String []args){

    /*    不使用springde 情况

         * //创建一个HelloWorld对象

        HelloWorld helloworld=new HelloWorld();

        //为对象赋值

        helloworld.setName("baixl");

        //调用hello()方法

        */

ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationcontext.xml");

HelloWorld helloworld=(HelloWorld) ctx.getBean("helloworld");

helloworld.hello();

}

}

运行结果:

最新文章

  1. div盒子垂直水平居中
  2. jdb - The Java Debugger
  3. sphinx :undefined reference to `libiconv&#39; 报错解决办法
  4. Cach&#233;数据库学习笔记(4)
  5. jquery/js实现验证聚焦,失焦
  6. simplify the design of the hardware forming the interface between the processor and thememory system
  7. mysql 字段编码该为utf8mb4
  8. mq_send
  9. Android子线程更新UI的方法总结
  10. DJANGO不同应用之间的用户迁移
  11. 盛希泰:办公室就像男人的春药——人的一生的精力是有限的,你把有限的时间分配给谁决定你的成败——你有N多选择,你人生的积累就是N多选择加起来的结果
  12. C#_传单小子
  13. hdu1443 Joseph---约瑟夫环
  14. MySQL-5.6.36-部署安装(编译版)
  15. Python调用ansible API系列(一)获取资产信息
  16. 杭电ACM2006--求奇数的乘积
  17. 重置sqlserver自增长列的种子
  18. 设计模式のBridgePattern(桥接模式)----结构模式
  19. [JDK8] Lambda
  20. Manjaro使用笔记-使用中国源的方法

热门文章

  1. HBase笔记之远程Shell界面命令行无法删除字符的解决方案
  2. Go语言 6 结构体、方法和接口
  3. 16级第二周寒假作业E题
  4. javashop每次重新部署都要从新安装的问题
  5. python基础===map, reduce, filter的用法
  6. openjudge-NOI 2.6-1759 最长上升子序列
  7. Web服务器处理动态程序三种方式及Apache配置
  8. java基础8 构造函数和构造代码块
  9. python【项目】:选课系统【简易版】
  10. socket-----爬虫&amp;&amp;文件传输