Spring:笔记整理(1)——HelloWorld
Spring:笔记整理(1)——HelloWorld
导入JAR包:
核心Jar包

Jar包解释
Spring-core
这个jar 文件包含Spring 框架基本的核心工具类。Spring 其它组件要都要使用到这个包里的类,是其它组件的基本核心,当然你也可以在自己的应用系统中使用这些工具类。
外部依赖Commons Logging, (Log4J)
Spring-Beans
这个jar 文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean 以及进行Inversion ofControl / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/ DI 支持,引入spring-core.jar 及spring-beans.jar 文件就可以了。外部依赖spring-core,(CGLIB)。
Spring-expression
Spring表达式语言。
Spring-Context
这个jar 文件为Spring 核心提供了大量扩展。可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI 所需的全部类,instrumentation组件以及校验Validation 方面的相关类。
外部依赖spring-beans, (spring-aop)。
Spring-aop
这个jar 文件包含在应用中使用Spring 的AOP 特性时所需的类和源码级元数据支持。
使用基于AOP 的Spring特性,如声明型事务管理(Declarative Transaction Management),也要在应用里包含这个jar包。
外部依赖spring-core, (spring-beans,AOP Alliance, CGLIB,Commons Attributes)。
开发步骤
1.编写接口及实现类
编写输出helloworld的接口及其实现类。
/*接口*/
package Beans;
public interface HelloApi {
public void sayHello();
}
————————————————————————————————————————————————————
/*实现类*/
package Beans;
public class HelloImp implements HelloApi{
public void sayHello() {
System.out.println("Hello");
}
}
2.编写配置文件
为了让Spring IOC来找到要管理的对象,我们需要编写配置文件进行配置。
<?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="Beans.HelloImp">
</bean>
</beans>
3.实例化IOC容器并从中获取所需对象
package Beans;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloWorld {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
HelloApi helloApi = context.getBean("helloworld",HelloImp.class);
helloApi.sayHello();
}
}
4.运行查看效果

Spring:笔记整理(1)——HelloWorld的更多相关文章
- Spring:笔记整理(2)——IOC容器
IOC容器 什么是IOC 说明 IOC ,全称Inversion of control,即,控制反转,是一种设计思想. 控制: 在Java中,IOC意味着:你将设计好的对象交给容器控制,而不是传统的在 ...
- Spring MVC 学习笔记1 - First Helloworld by Eclipse【& - java web 开发Tips集锦】
Spring MVC 学习笔记1 - First Helloworld by Eclipse reference:http://www.gontu.org 1. 下载 Spring freamwork ...
- 运维开发笔记整理-使用Django编写helloworld
运维开发笔记整理-使用Django编写helloworld 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.创建Django项目 1>.创建Django项目 djang ...
- java笔记整理
Java 笔记整理 包含内容 Unix Java 基础, 数据库(Oracle jdbc Hibernate pl/sql), web, JSP, Struts, Ajax Spring, E ...
- python学习笔记整理——字典
python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...
- 从0开始学Swift笔记整理(五)
这是跟在上一篇博文后续内容: --Core Foundation框架 Core Foundation框架是苹果公司提供一套概念来源于Foundation框架,编程接口面向C语言风格的API.虽然在Sw ...
- 基于XML配置的Spring MVC 简单的HelloWorld实例应用
1.1 问题 使用Spring Web MVC构建helloworld Web应用案例. 1.2 方案 解决本案例的方案如下: 1. 创建Web工程,导入Spring Web MVC相关开发包. Sp ...
- Deep Learning(深度学习)学习笔记整理系列之(五)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Hadoop学习笔记(5) ——编写HelloWorld(2)
Hadoop学习笔记(5) ——编写HelloWorld(2) 前面我们写了一个Hadoop程序,并让它跑起来了.但想想不对啊,Hadoop不是有两块功能么,DFS和MapReduce.没错,上一节我 ...
随机推荐
- grub.conf文件说明
default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Red Hat Enterprise Linux ...
- 矩阵中的路径 剑指offer65题
include "stdafx.h" #include<vector> #include<algorithm> #include<string> ...
- jsp中怎么隐藏from表 和一些按钮?
给你提供两种方法:1.style.display="none"2.添加margen-left属性,值赋为负数,页面上有,但是不会显示
- linux grep sed awk
$ grep ‘test’ d* 显示所有以d开头的文件中包含 test的行. $ grep ‘test’ aa bb cc 显示在aa,bb,cc文件中匹配test的行. $ grep ‘[a-z] ...
- openstack组件通讯端口定义
openstack 组件通讯是通过ZeroMQ+ceilometer发送组件调用信息,具体是通过TCP通讯,发送数据和接收数据是用同一个端口(在配置文件指定),下面通过代码稍作解析: IceHouse ...
- Python gevent学习笔记
gevent是Python的一个用于网络IO的函数库,其中应用到了 coroutine(协同程序) 的思想.首先来了解下目前网络框架的几种基本的网络I/O模型: 阻塞式单线程:这是最基本的I/O模型, ...
- artDialog自定义弹框
弹框内容:<div class='boxy' style="display:none;" id="boxy"> //将div设置成隐藏效果 < ...
- 辛星教你高速掌握PHP的正則表達式
首先说一下,这篇文章也是我在看了数个大牛的博客之后总结出来的,因此首先向这些大牛表示崇高的敬意和感谢,因为人数众多.并且来源也是特别分散,就不一一介绍了,见谅. ************跨语言的主题* ...
- 7、easyui 表单
这是最后一个小节了,后面将会使用一个小项目来进一步实用讲解: 在之前的什么相关只是点都以及讲过了或者说涉及到过,如datagrid表格,树形菜单,布局面板panel,页签,拖放功能,只是在表格的属性细 ...
- POJ1751 Highways
题目链接 http://poj.org/problem?id=1751 题目大意:输入n:然后给你n个点的坐标(任意两点之间皆可达):输入m:接下来m行每行输入两个整数x,y表示 点x与点y 已 ...