[Spring]初识Spring-Spring是什么?如何实例化一个Spring容器?
关于Spring入门的基础知识点
Spring简介
Spring是由Rod Johnson创建的轻量型容器,目的在于简化企业级开发。是一种容器框架
a.降低侵入性
b.提供了IOC(控制反转)和AOP(面向切面)的功能,可以降低组件之间的耦合度,便于系统的维护和升级
c. 为系统提供一个整体的解决方案,开发者除了能够使用其本身的功能以外,还可以将Spring框架和其他框架整合可以自由选择采用暗中技术来架构项目
总结:Spring框架的实质是管理软件中的对象,可以对软件中对象的创建以及对象间的依赖关系进行管理
优点
Spring中的模块
Spring框架由七个定义明确的模块组成
如果作为一个整体,这些模块为你提供了开发企业应用所需的一切。但你不必将应用完全基于Spring框架。你可以自由地挑选适合你的应用的模块而忽略其余的模块。
所有的Spring模块都是在核心容器之上构建的。容器定义了Bean是如何创建、配置和管理的。当你配置你的应用时,你会潜在地使用这些类。但是作为一名开发者,你最可能对影响容器所提供的服务的其它模块感兴趣。这些模块将会为你提供用于构建应用服务的框架,例如AOP和持久性。

更详细的可以参考百度百科:https://baike.baidu.com/item/spring%E6%A1%86%E6%9E%B6/2853288
A.Spring中的容器
在Spring中,所有的Java类都当成JavaBean来处理,这些Bean通过容器进行管理和使用。
这些类要满足下面几个规范:
1,是公共的类,并且含有公有的无参构造法方法
2,实例变量私有化提供 get / set 方法
Spirng中的容器中常用的两个管理对象的类是 BeanFactory和ApplicationContext两个,区别是
ApplicationContext继承了BeanFactory,因此含有更多的企业级的方法。并且两者都是接口。
使用中 BeanFactory 比较高效一些
B.Spring容器的实例化
1,导入相关 jar 包(先放在 src / lib 下)
2,在项目中加入Spirng配置文件 applicationContext.xml
3,使用BeanFactory或ApplicationContext 创建容器,只需要创建一个就足够了
配置文件: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" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> </beans>
Demo01.java
//相对路径
ApplicationContext ac=new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
//绝对路径
ApplicationContext ac2=new FileSystemXmlApplicationContext("src"+File.separator+"applicationContext.xml");
System.out.println(ac2);
// 关闭容器
((AbstractApplicationContext) ac).close();
[Spring]初识Spring-Spring是什么?如何实例化一个Spring容器?的更多相关文章
- 集群: 如何在spring 任务中 获得集群中的一个web 容器的端口号?
系统是两台机器, 跑四个 web 容器, 每台机器两个容器 . nginx+memcached+quartz集群,web容器为 tomcat . web 应用中 用到spring 跑多个任务,任务只能 ...
- 【Spring学习笔记-2】Myeclipse下第一个Spring程序-通过ClassPathXmlApplicationContext加载配置文件
*.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...
- Spring boot 官网学习笔记 - 开发第一个Spring boot web应用程序(使用mvn执行、使用jar执行)
Creating the POM <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...
- Spring入门教程:通过MyEclipse开发第一个Spring项目
Animal.java package com.project; public class Animal { private String name; public String getName() ...
- 五分钟,手撸一个Spring容器!
大家好,我是老三,Spring是我们最常用的开源框架,经过多年发展,Spring已经发展成枝繁叶茂的大树,让我们难以窥其全貌. 这节,我们回归Spring的本质,五分钟手撸一个Spring容器,揭开S ...
- 只需两步!Eclipse+Maven快速构建第一个Spring Boot项目
随着使用Spring进行开发的个人和企业越来越多,Spring从一个单一简介的框架变成了一个大而全的开源软件,最直观的变化就是Spring需要引入的配置也越来越多.配置繁琐,容易出错,让人无比头疼, ...
- 用 Docker 构建、运行、发布来一个 Spring Boot 应用
本文演示了如何用 Docker 构建.运行.发布来一个 Spring Boot 应用. Docker 简介 Docker 是一个 Linux 容器管理工具包,具备“社交”方面,允许用户发布容器的 im ...
- Spring初识(通过小实例清晰认识Spring)
1.spring架构: spring是J2EE应用程序框架,是轻量级的IoC和AOP的容器框架,主要是针对javaBean的生命周期进行管理的轻量级容器,可以单独使用,也可以和Struts框架,iba ...
- spring的bean是在什么时候实例化的
如果没有特殊配置,当bean的scope为原型,也就是singleton的时候,在启动spring容器的时候完成实例化.且需要注意的是,当实例化一个bean的时候,先执行其构造函数代码,然后再执行se ...
随机推荐
- Find the duplicate Number (鸽巢原理) leetcode java
问题描述: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive ...
- climbing stairs leetcode java
问题描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either ...
- grep 和curl -d等命令 单引号里面既使用正则,又使用变量的方法
a='{"type":"d_log", "log_format":"d_log", "exclude" ...
- zsh切换bash bash切换zsh
切换bash(需要sudo) chsh -s /bin/bash 切换zsh(不需要sudo) chsh -s /bin/zsh 注意:如果输入命令和密码后提示:no change made. 请加上 ...
- C++ leetcode::two sum
上完C++的课就在也没用过C++了,最近要找实习,发现自己没有一门语言称得上是熟练,所以就重新开始学C++.记录自己从入门到放弃的过程,论C++如何逼死花季少女. 题目:Given an array ...
- 微信小程序: rpx与px,rem相互转换
官方上规定屏幕宽度为20rem,规定屏幕宽为750rpx,则1rem=750/20rpx. 微信官方建议视觉稿以iPhone 6为标准:在 iPhone6 上,屏幕宽度为375px,共有750个物理像 ...
- 微信小程序 带参调用后台接口 循环渲染页面 wx.request wx:for
test.js 文件里的onLoad function getarticles(p,order,mythis) { wx.request({ url: 'https://ganggouo.cn/ind ...
- axur axure rp安装
axure rp安装 1◆ axure rp 文件下载 2◆创建安装目录 3◆ 安装图解 4◆汉化 替换 5◆ 使用 success
- SQLite 剖析
由于sqlite对多进程操作支持效果不太理想,在项目中,为了避免频繁读写 文件数据库带来的性能损耗,我们可以采用操作sqlite内存数据库,并将内存数据库定时同步到文件数据库中的方法. 实现思路如下: ...
- ubuntu16.10安装搜狗输入法
一.搜狗输入法安装 1.首先到搜狗输入法官网下载搜狗输入法,下载的是个deb文件. 搜狗输入法Linux版下载地址:http://pinyin.sogou.com/linux/?r=pinyin 2. ...