1.Spring学习笔记_HelloWorld(by尚硅谷_佟刚)
来源:互联网 发布:网络应急预案演练记录 编辑:程序博客网 时间:2024/04/29 05:30
一、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尚硅谷_佟刚)
- 3.Spring学习笔记_配置Bean(by尚硅谷_佟刚)
- 4.Spring学习笔记_属性配置细节(by尚硅谷_佟刚)
- 5.Spring学习笔记_自动装配(by尚硅谷_佟刚)
- 8.Spring学习笔记_使用外部属性文件(by尚硅谷_佟刚)
- 10.Spring学习笔记_管理Bean的生命周期(by尚硅谷_佟刚)
- 12.Spring学习笔记_通过FactoryBean配置Bean(by尚硅谷_佟刚)
- 13.Spring学习笔记_通过注解配置Bean(by尚硅谷_佟刚)
- 14.Spring学习笔记_泛型依赖注入(by尚硅谷_佟刚)
- 16.Spring学习笔记_前置通知&后置通知(by尚硅谷_佟刚)
- 18.Spring学习笔记_切面的优先级(by尚硅谷_佟刚)
- 19.Spring学习笔记_重用切点表达式(by尚硅谷_佟刚)
- 2.Spring学习笔记_IOC&DI概述(by尚硅谷_佟刚)
- 6.Spring学习笔记_Bean之间的关系 (by尚硅谷_佟刚)
- 7.Spring学习笔记_Bean的作用域(by尚硅谷_佟刚)
- 9.Spring学习笔记_SpEL(by尚硅谷_佟刚)
- 15.Spring学习笔记_AOP基础(by尚硅谷_佟刚)
- 11.Spring学习笔记_通过工厂方法配置Bean(by尚硅谷_佟刚)
- SQL语句优化
- ImageLoader加载图片,实现原理。。。
- Oracle序列号
- 企业帐号进行IPA的打包的详细流程(我是部署到蒲公英上面的,注册上传应用即可,这里就不说了很简单)
- Oracle索引
- 1.Spring学习笔记_HelloWorld(by尚硅谷_佟刚)
- IntelliJ IDEA设置
- 互联网开发3--Dubbo框架
- 把普通路由器扩展为WIFI广告路由器
- spin constrol与edit 控件共用
- IntelliJ IDEA常用快捷键
- python读写配置文件
- IntelliJ IDEA SVN 中英文对照
- 将异常信息 转换成 字符串 输出