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.没错,上一节我 ...
随机推荐
- plsql programming 08 字符串
一般, char 和 nchar 类型很少使用. 建议使用 varchar2 和 nvarchar2, 其中( n 开头的是国家字符集, 没有n开头的是数据库字符集 ) 一般也不怎么使用国家字符集 v ...
- spark 1.3 发布了
悄悄地,spark 还是像往常一样,发布了1.3版本,从release notes可以看出,这一版本比较大的变化是1. 增加了DataFrame API,这样以后操作一些结构化的数据集时将会变的非常方 ...
- 创建一个视图JSP文件的helloWorld.jsp
让我们创建下面的JSP文件的helloWorld.jsp,在WebContent文件夹在你的eclipse项目.要做到这一点,右键单击WebContent文件夹中的项目资源管理器,然后选择“新建”&g ...
- Shell脚本之监视指定进程的执行状态
在之前的博客中,以前写了自己主动化測试程序的实现方法,如今开发人员须要知道被測试的进程(在此指执行在LINUX上的主进程的)在异常退出之前的进程的执行状态,比如内存的使用率.CPU的使用率等. 现用s ...
- js的一些技巧总结
1. 将彻底屏蔽鼠标右键 <body oncontextmenu="return false"> ''''' </body> 或者 <table b ...
- Linq源代码阅读
在 System.Core dotnet451\source\ndp\fx\src\core\system\linq\enumerable.cs Where 和 Select 内 ,把数组和List分 ...
- PostgreSQL tips
tip 1 在sql中我们可以设置一个列自增长identity(1,1),但在postgresql中却没有这个关键字定义.但postgresql也有实现相关功能,那就是只需要将该列数据类型标记为ser ...
- Python Socket套接字
socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. socket起源于Un ...
- go语言调用cmd
package main import ( "fmt" "os/exec" ) func main() { //删除C:\Users\Administrator ...
- Laravel5.1 Migration数据库迁移文件
Migration方便于团队开发,它就像数据库的版本控制一样,它的功能就是可以和别人共享你的数据库结构.这么说可能不太好理解,你跟着敲敲就明白了. 0 前提工作-配置数据库 找到你根目录的 .env ...