1.Spring学习笔记_HelloWorld(by尚硅谷_佟刚)
一、Spring是什么
Spring 是一个开源框架。
Spring 为简化企业级应用开发而生(主要针对EJB2来说),使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能。
Spring 是一个 IOC(DI) 和 AOP 容器框架。
二、具体描述Spring
轻量级:Spring 是非侵入性的 - 基于 Spring 开发的应用中的对象可以不依赖于 Spring 的 API
依赖注入(DI --- dependency injection、IOC)
面向切面编程(AOP --- aspect oriented programming)
容器: Spring 是一个容器, 因为它包含并且管理应用对象的生命周期
框架: Spring 实现了使用简单的组件配置组合成一个复杂的应用. 在 Spring 中可以使用 XML 和 Java 注解组合这些对象
一站式:在 IOC 和 AOP 的基础上可以整合各种企业应用的开源框架和优秀的第三方类库 (实际上 Spring 自身也提供了展现层的 SpringMVC 和 持久层的 Spring JDBC)
三、Spring模块
四、安装 SPRING TOOL SUITE
SPRING TOOL SUITE 是一个 Eclipse 插件,利用该插件可以更方便的在 Eclipse 平台上开发基于 Spring 的应用。
安装方法说明(springsource-tool-suite-3.4.0.RELEASE-e4.3.1-updatesite.zip):
1.Help --> Install New Software...
2.Click Add...
3.In dialog Add Site dialog, click Archive...
4.Navigate to springsource-tool-suite-3.4.0.RELEASE-e4.3.1-updatesite.zip and click Open
5.Clicking OK in the Add Site dialog will bring you back to the dialog 'Install'
6.Select the xxx/Spring IDE that has appeared
7.Click Next and then Finish
8.Approve the license
9.Restart eclipse when that is asked
五、搭建 Spring 开发环境
1、创建maven工程
2、配置pom.xml引入spring的jar包
<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.4.RELEASE</version></dependency>
</dependencies>
3、Spring 的配置文件:
一个典型的 Spring 项目需要创建一个或多个 Bean 配置文件, 这些配置文件用于在 Spring IOC 容器里配置 Bean. Bean 的配置文件可以放在 classpath 下, 也可以放在其它目录下
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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><bean id="helloWorld" class="cn.wwy.spring.base.HelloWorld"><property name="user" value="Spring"></property></bean></beans>
4、建立Spring项目
public class HelloWorld {private String user;public HelloWorld() {System.out.println("HelloWorld's constructor...");}public void setUser(String user) {System.out.println("setUser:" + user);this.user = user;}public HelloWorld(String user) {this.user = user;}public void hello(){System.out.println("Hello: " + user);}}
public class Main {public static void main(String[] args) {// HelloWorld helloWorld = new HelloWorld();
// helloWorld.setUser("Tom");
// helloWorld.hello(); //1.创建Spring的IOC容器对象ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");//2.从IOC容器中获取bean实例HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");//3.调用hello方法helloWorld.hello();}}
5、运行结果
1.Spring学习笔记_HelloWorld(by尚硅谷_佟刚)相关推荐
- JavaWeb学习总结——JavaWEB_Servlet(尚硅谷_佟刚老师)
JavaWEB_Servlet(尚硅谷_佟刚老师) (本文档是在学习尚硅谷_佟刚老师的JavaWeb教学视频时写的,特此感谢) 1. 使用 JavaEE版的 Eclipse开发动态的 WEB工程(Ja ...
- JavaWeb学习总结——JavaWEB_JSP(尚硅谷_佟刚老师)
1. JSP: 1). WHY: JSP 是简Servlet 编写的一种技术, JSP = Java(动态) + HTML(静态页面) 2). Java ServerPage: Java 服务器端网页 ...
- Spring 学习笔记 3. 尚硅谷_佟刚_Spring_配置 Bean
1,bean 的配置 <bean id="helloWorld" class="com.yfy.HelloWorld"><property n ...
- 8.Spring学习笔记_使用外部属性文件(by尚硅谷_佟刚)
使用外部属性文件 在配置文件里配置 Bean 时, 有时需要在 Bean 的配置里混入系统部署的细节信息(例如: 文件路径, 数据源配置信息等). 而这些部署细节实际上需要和 Bean 配置相分离 S ...
- 6.Spring学习笔记_Bean之间的关系 (by尚硅谷_佟刚)
一.继承 Bean 配置 Spring 允许继承 bean 的配置, 被继承的 bean 称为父 bean. 继承这个父 Bean 的 Bean 称为子 Bean 子 Bean 从父 Bean 中继承 ...
- 20.Spring学习笔记_基于配置文件的方式来配置 AOP(by尚硅谷_佟刚)
基于 XML 的配置声明切面 除了使用 AspectJ 注解声明切面, Spring 也支持在 Bean 配置文件中声明切面. 这种声明是通过 aop schema 中的 XML 元素完成的. 正常情 ...
- 18.Spring学习笔记_切面的优先级(by尚硅谷_佟刚)
指定切面的优先级 在同一个连接点上应用不止一个切面时, 除非明确指定, 否则它们的优先级是不确定的. 切面的优先级可以通过实现 Ordered 接口或利用 @Order 注解指定. 实现 Ordere ...
- 尚硅谷_佟刚_SpringMVC_工程实例与代码(自己敲的)
https://pan.baidu.com/s/1vagDwamZEQPH5DIHU-IXTQ
- Redis学习笔记(转尚硅谷周阳)
教学视频 Redis官网 Redis中文官网 一.NoSQL入门概述-上 1.互联网时代背景下大机遇,为什么用NoSQL 1.1.单机MySQL的美好年代 在90年代,一个网站的访问量一般都不大,用单 ...
最新文章
- 如何测服务器网站带宽,windows服务器如何测试带宽速度?
- EOS资源模型(2)资源使用
- alchemy php,Python下SQLAlchemy的简单介绍
- 计算机系统的工作方式,某计算机系统输入/输出采用双缓冲工作方式,其工作过程如下图所示,假设磁盘块与缓冲 - 信管网...
- 启动不起来_国产开源工具:U盘启动工具Ventoy v1.0.29发布——墨涩网
- ssh 免密码登录远程主机 免登录运行指令
- Spring4.x()---JdbcDaoSupport的使用
- Node组件——Express简介
- java top tree 数据结构_Java中如何实现Tree的数据结构算法
- 软件工程师的衰落与程序员的崛起
- matlab data数据类型,MATLAB - 数据类型
- C语言n番战--数组(三)
- 整站优化与网页优化的区别
- 【短视频运营】查找对标账号 ( 关键词搜索 | 第三方工具查找 | 对标账号学习 | 视频文案 | #话题 | 评论内容 | 历史视频 )
- 拉杰尔安卓服务器注册上限,航海王启航409区圣地玛丽杰尔开服时间表_航海王启航新区开服预告_第一手游网手游开服表...
- 「群体遗传学实战」第一课: 对SNP位点进行注释
- Netty介绍与实战(三)之粘包拆包
- 阿里云购买域名到icp备案
- 一点关于优化手写笔迹
- Sybase roseha 双机(转)
热门文章
- 视频批量截取方法,怎样同时对多个视频的一部分进行截取?
- win 2016 ssh_【Win】Print Conductor 全能批量打印工具兼容所有打印机
- WIN10桌面图标变成白文件的一种解决方法
- compare和compareTo使用区别
- 发明计算机作文300字,四年级我的发明作文300字
- 网络-4 【http状态码、accept、Content-Type】
- HTML标签 链接 CSS样式
- 把 GPL 视作“病毒”?请停止污名化 GPL
- 解释一下什么是鲁棒性
- matlab求解振动学问题,振动力学基础与MATLAB应用