第一节:Spring 简介

Spring 作者:Rod Johnson;

官方网站:http://spring.io/

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

核心思想:IOC 控制反转;AOP 面向切面;(这是学习spring的两个重点中的重点)

介绍:百度百科;

第二节:Spring4 版Hello World 实现

核心jar包:

百度云下载:http://pan.baidu.com/s/1jIEphqQ

密码:3xb3

beans.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的jar包

beans.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 id="helloWorld" class="com.wishwzp.test.HelloWorld"></bean> </beans>

HelloWorld.java

package com.wishwzp.test;

public class HelloWorld {

    public void say(){
System.out.println("Spring4你好!");
}
}

Test.java

package com.wishwzp.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wishwzp.test.HelloWorld; public class Test { public static void main(String[] args) {
ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");
HelloWorld helloWorld=(HelloWorld)ac.getBean("helloWorld");
helloWorld.say();
}
}

说明:beans.xml文件在src目录下面,以为使用的是ClassPathXmlApplicationContext,会根据classpath加载。

还有一种是FileSystemXmlApplicationContext,根据文件绝对路径去查找

运行结果显示:

最新文章

  1. Windows2012R2备用域控搭建
  2. 进军Linux
  3. mvc路由注意事项
  4. PAT乙级 1029. 旧键盘(20)
  5. OpenJudge就算概论-最长单词2【寻找句子内部最长的单词】
  6. &lt;转载&gt;gcc/g++编译
  7. SaaS系列介绍之四:我国SaaS市场发展
  8. Git基本操作(Windows下)
  9. information_schema.key_column_usage 学习
  10. Javascript进阶篇——( JavaScript内置对象---上-Date,string,charAt,indexOf,split,substring,substr)笔记整理
  11. 程序员带你一步步分析AI如何玩Flappy&#160;Bird
  12. python3之OS与sys模块
  13. 杭电ACM 1003题
  14. grafana备份
  15. java.util.LinkedHashMap cannot be cast to xxx 和 net.sf.ezmorph.bean.MorphDynaBean cannot be cast to xxx
  16. 剑指offer--2.替换空格
  17. vim小技巧2
  18. python基础08_set集合
  19. android 布局文件 ScrollView 中的 listView item 显示不全解决方案
  20. vc++获取网页源码之使用import+接口方式

热门文章

  1. hdoj 1106 排序
  2. 转载ASP.NET MVC 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction区别
  3. 转载 DevOps的基本原则与介绍
  4. java类的访问控制符与其他几个特殊修饰符的总结
  5. java学习之路---线程(重点)
  6. Finite Difference Method with Mathematica
  7. HBase在京东的完善与创新
  8. linux下配置squid http proxy过程
  9. ios 说一说UINavigationController 的堆栈
  10. iBatis调用存储过程以及MySQL创建存储过程