一、Spring IOC容器---- Spring AllicationContext容器

程序的结构如下:

1.首先在MyEclipse 创建创建Java Project

2.创建好后,添加sping支持。在project上右击, MyEclipse->Add spring Capabilities.

3.之后会自动生成applicationContent.xml文件

1)创建HelloWorld.java

1
2
3
4
5
6
7
8
9
10
public class HelloWorld {
    private String message;
       public void setMessage(String message){
          this.message  = message;
       }
       public void getMessage(){
          System.out.println("Your Message : " + message);
       }
}

2)创建MainApp.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class MainApp {
    /**
     * @param args
     */
    public static void main(String[] args) {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("applicationContext.xml");
        HelloWorld obj = (HelloWorld)context.getBean("helloWorld");
        obj.getMessage();
    }
}

 3)在applicationContent.xml文件配置如下:

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="helloWorld" class="bu.example.com.HelloWorld">
        <property name="message" value="Hello World!!!" />
    </bean>
</beans>

4.最后运行,结果如下:

  

 

二、Spring IOC容器---- Spring BeanFactory容器

只需修改MainApp.java文件

1
2
3
4
5
6
public static void main(String[] args) {
        XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
        HelloWorld obj = (HelloWorld)factory.getBean("helloWorld");
        obj.getMessage();
    }

 两个输出的效果是一样的。 

1.spring jar包下载地址

spring官网的改变,导致找不到下载地址:

spring framework download site

http://maven.springframework.org/release/org/springframework/spring/

(参考)

2. spring教程 参考 使用Eclipse IDE

本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/p/5177045.html,如需转载请自行联系原作者

MyEclipse Spring 学习总结一 Spring IOC容器相关推荐

  1. 转 Spring源码剖析——核心IOC容器原理

    Spring源码剖析--核心IOC容器原理 2016年08月05日 15:06:16 阅读数:8312 标签: spring 源码 ioc 编程 bean 更多 个人分类: Java https:// ...

  2. JavaEE——Spring学习笔记01【Ioc开发的模式】

    JavaEE--Spring学习笔记01[Ioc开发的模式] JavaEE--Spring学习笔记02[Spring和Mybatis的整合] JavaEE--Spring学习笔记03[AOP开发] J ...

  3. 【spring源码分析】IOC容器初始化(二)

    前言:在[spring源码分析]IOC容器初始化(一)文末中已经提出loadBeanDefinitions(DefaultListableBeanFactory)的重要性,本文将以此为切入点继续分析. ...

  4. Spring中将BeanDefinition注册到IOC容器中

    Spring中将BeanDefinition注册到IOC容器中 XML配置元信息 <bean name="-" - /> 注解: @Bean,@Component,@I ...

  5. Spring学习(四)IOC详解

    本文借鉴:Spring学习(特此感谢!) 一.简介 概念:控制反转是一种通过描述(在 Java 中可以是 XML 或者注解)并通过第三方(Spring)去产生或获取特定对象的方式.(被动创建) 优势: ...

  6. 六、spring之通过FactoryBean为ioc容器中添加组件

    前面我们已经介绍了几种为容器中添加组件的方法,今天一起学习通过FactoryBean添加组件的方法. 首先我们准备一个类,也就是我们需要注册进spring的ioc容器中的类 类Color: // 不必 ...

  7. spring学习笔记(spring概述和IOC)

    spring5 1.spring的概述 1.1.spring是什么 Spring 是于 2003 年兴起的一个轻量级的 Java 开发框架,它是为了解决企业应用开发的复杂性而创建的. Spring 的 ...

  8. Spring学习笔记1:IOC本质和依赖注入

    文章目录 1.IOC本质 1.1.拓展:关于Spring Boot 和 Spring Cloud 2.HelloSpring 3.IOC创建对象的方式 4.Spring配置 4.1.别名 4.2.Be ...

  9. Spring学习笔记:2(IOC装配Bean之xml方式)

    xml配置方式装配Bean 本文借鉴于:https://www.cnblogs.com/qdhxhz/p/6511887.html Spring框架Bean实例化的方式提供了三种方式实例化Bean 构 ...

最新文章

  1. 使用CSDN-markdown编辑器
  2. PIE SDK热力图
  3. python开发专属表情包_Python开发个人专属表情包网站
  4. 软件工程导论第六周作业:关于servlet,jquery,ExtJs,Spket
  5. 14门教程带你全面入门Linux
  6. 【图像处理】——鼠标点击图像的一处,获得点击点的坐标值
  7. 利用python模拟菜刀反弹shell绕过限制
  8. 输出绝对值(信息学奥赛一本通-T1040)
  9. linux时间类型localtime_r
  10. 首页 、引导页、版本
  11. Python在使用pip安装某个库时报错 Could not find a version that satisfies the requirement numpy
  12. c语言+游戏破解,c语言获得键盘的按键
  13. Small game written by Python 2021/1/7
  14. 使用PHP和JS对小米主题商店下载地址解析
  15. 现在唯一可以得到卡巴斯基激活码的地方
  16. python找色_利用python检测色情图片简易实例
  17. Qt--ipad滑屏效果
  18. IP地址的认识(一)
  19. 如何安装Python中numpy,在DOS验证下一步步解决安装问题(DOS下从python的验证到pip验证到Numpy安装成功)
  20. ERROR: Cannot install keras==2.2.0 and tensorflow==1.14.0 because these package versions have confli

热门文章

  1. 箱线图怎么判断异常值_原创【六西格玛工具解读】02——箱线图(Boxplot)
  2. 修改所有列_宝塔面板安装完的一些列操作
  3. 与自定义词典 分词_如何掌握分词技术,你需要学会这些
  4. 主板uefi和传统引导方式区别_反吊膜与传统污水池加盖方式有什么区别
  5. python爬取下拉列表数据_Python怎么爬取下拉式的网页?
  6. ad用户和计算机的使用方法,AD技巧之指定用户登录和指定计算机登陆
  7. centos 6.3安装mysql_centos6.3安装MySQL 5.6(转)
  8. 基于超声波升压中周构建的150kHz的单管选频放大电路
  9. 最温暖的大学,最火热的比赛
  10. DRV8825步进电机驱动控制模块以及双轴平台